class Roadie::Rails::Options

Constants

ATTRIBUTE_NAMES

Public Class Methods

new(options = {}) click to toggle source
# File lib/roadie/rails/options.rb, line 15
def initialize(options = {})
  complain_about_unknown_keys options.keys
  self.after_transformation     = options[:after_transformation]
  self.asset_providers          = options[:asset_providers]
  self.before_transformation    = options[:before_transformation]
  self.external_asset_providers = options[:external_asset_providers]
  self.keep_uninlinable_css     = options[:keep_uninlinable_css]
  self.url_options              = options[:url_options]
end

Public Instance Methods

after_transformation=(callback) click to toggle source
# File lib/roadie/rails/options.rb, line 33
def after_transformation=(callback)
  @after_transformation = callback
end
apply_to(document) click to toggle source
# File lib/roadie/rails/options.rb, line 59
def apply_to(document)
  document.url_options = url_options
  document.before_transformation = before_transformation
  document.after_transformation = after_transformation

  document.asset_providers = asset_providers if asset_providers
  document.external_asset_providers = external_asset_providers if external_asset_providers

  document.keep_uninlinable_css = keep_uninlinable_css unless keep_uninlinable_css.nil?
end
asset_providers=(providers) click to toggle source
# File lib/roadie/rails/options.rb, line 41
def asset_providers=(providers)
  if providers
    @asset_providers = ProviderList.wrap providers
  # TODO: Raise an error when setting to nil in order to make this not a silent error.
  # else
  #   raise ArgumentError, "Cannot set asset_providers to nil. Set to Roadie::NullProvider if you want no external assets inlined."
  end
end
before_transformation=(callback) click to toggle source
# File lib/roadie/rails/options.rb, line 29
def before_transformation=(callback)
  @before_transformation = callback
end
combine(options) click to toggle source
# File lib/roadie/rails/options.rb, line 81
def combine(options)
  dup.combine! options
end
combine!(options) click to toggle source
# File lib/roadie/rails/options.rb, line 85
def combine!(options)
  self.after_transformation = combine_callable(
    after_transformation, options[:after_transformation]
  )

  self.asset_providers = combine_providers(
    asset_providers, options[:asset_providers]
  )

  self.before_transformation = combine_callable(
    before_transformation, options[:before_transformation]
  )

  self.external_asset_providers = combine_providers(
    external_asset_providers, options[:external_asset_providers]
  )

  self.keep_uninlinable_css =
    options[:keep_uninlinable_css] if options.has_key?(:keep_uninlinable_css)

  self.url_options = combine_hash(
    url_options, options[:url_options]
  )

  self
end
external_asset_providers=(providers) click to toggle source
# File lib/roadie/rails/options.rb, line 50
def external_asset_providers=(providers)
  if providers
    @external_asset_providers = ProviderList.wrap providers
  # TODO: Raise an error when setting to nil in order to make this not a silent error.
  # else
  #   raise ArgumentError, "Cannot set asset_providers to nil. Set to Roadie::NullProvider if you want no external assets inlined."
  end
end
keep_uninlinable_css=(bool) click to toggle source
# File lib/roadie/rails/options.rb, line 37
def keep_uninlinable_css=(bool)
  @keep_uninlinable_css = bool
end
merge(options) click to toggle source
# File lib/roadie/rails/options.rb, line 70
def merge(options)
  dup.merge! options
end
merge!(options) click to toggle source
# File lib/roadie/rails/options.rb, line 74
def merge!(options)
  ATTRIBUTE_NAMES.each do |attribute|
    send "#{attribute}=", options.fetch(attribute, send(attribute))
  end
  self
end
url_options=(options) click to toggle source
# File lib/roadie/rails/options.rb, line 25
def url_options=(options)
  @url_options = options
end

Private Instance Methods

combine_callable(first, second) click to toggle source
# File lib/roadie/rails/options.rb, line 119
def combine_callable(first, second)
  combine_nilable(first, second) do |a, b|
    proc { |*args| a.call(*args); b.call(*args) }
  end
end
combine_hash(first, second) click to toggle source
# File lib/roadie/rails/options.rb, line 113
def combine_hash(first, second)
  combine_nilable(first, second) do |a, b|
    a.merge(b)
  end
end
combine_nilable(first, second) { |first, second| ... } click to toggle source
# File lib/roadie/rails/options.rb, line 131
def combine_nilable(first, second)
  if first && second
    yield first, second
  else
    first ? first : second
  end
end
combine_providers(first, second) click to toggle source
# File lib/roadie/rails/options.rb, line 125
def combine_providers(first, second)
  combine_nilable(first, second) do |a, b|
    ProviderList.new(a.to_a + Array.wrap(b))
  end
end
complain_about_unknown_keys(keys) click to toggle source
# File lib/roadie/rails/options.rb, line 139
def complain_about_unknown_keys(keys)
  invalid_keys = keys - ATTRIBUTE_NAMES
  if invalid_keys.size > 0
    raise ArgumentError, "Unknown configuration parameters: #{invalid_keys}", caller(1)
  end
end