class Roadie::Rails::Options

Constants

ATTRIBUTE_NAMES

Attributes

after_transformation[W]
before_transformation[W]
keep_uninlinable_css[W]
url_options[W]

Public Class Methods

new(options = {}) click to toggle source
# File lib/roadie/rails/options.rb, line 24
def initialize(options = {})
  complain_about_unknown_keys options.keys
  options.each_pair do |name, value|
    self[name] = value
  end
end

Public Instance Methods

[](option) click to toggle source
# File lib/roadie/rails/options.rb, line 99
def [](option)
  if ATTRIBUTE_NAMES.include?(option)
    public_send(option)
  else
    raise ArgumentError, "#{option.inspect} is not a valid option"
  end
end
[]=(option, value) click to toggle source
# File lib/roadie/rails/options.rb, line 107
def []=(option, value)
  if ATTRIBUTE_NAMES.include?(option)
    public_send(:"#{option}=", value)
  else
    raise ArgumentError, "#{option.inspect} is not a valid option"
  end
end
apply_to(document) click to toggle source
# File lib/roadie/rails/options.rb, line 47
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

  if external_asset_providers
    document.external_asset_providers = external_asset_providers
  end

  unless keep_uninlinable_css.nil?
    document.keep_uninlinable_css = keep_uninlinable_css
  end
end
asset_providers=(providers) click to toggle source
# File lib/roadie/rails/options.rb, line 31
def asset_providers=(providers)
  # TODO: Raise an error when setting to nil in order to make this not a
  # silent error.
  if providers
    @asset_providers = ProviderList.wrap providers
  end
end
combine(options) click to toggle source
# File lib/roadie/rails/options.rb, line 74
def combine(options)
  dup.combine! options
end
combine!(options) click to toggle source
# File lib/roadie/rails/options.rb, line 78
def combine!(options)
  %i[after_transformation before_transformation].each do |name|
    self[name] = Utils.combine_callable(self[name], options[name])
  end

  %i[asset_providers external_asset_providers].each do |name|
    self[name] = Utils.combine_providers(self[name], options[name])
  end

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

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

  self
end
external_asset_providers=(providers) click to toggle source
# File lib/roadie/rails/options.rb, line 39
def external_asset_providers=(providers)
  # TODO: Raise an error when setting to nil in order to make this not a
  # silent error.
  if providers
    @external_asset_providers = ProviderList.wrap providers
  end
end
merge(options) click to toggle source
# File lib/roadie/rails/options.rb, line 63
def merge(options)
  dup.merge! options
end
merge!(options) click to toggle source
# File lib/roadie/rails/options.rb, line 67
def merge!(options)
  ATTRIBUTE_NAMES.each do |attribute|
    self[attribute] = options.fetch(attribute, self[attribute])
  end
  self
end

Private Instance Methods

complain_about_unknown_keys(keys) click to toggle source
# File lib/roadie/rails/options.rb, line 117
def complain_about_unknown_keys(keys)
  invalid_keys = keys - ATTRIBUTE_NAMES
  unless invalid_keys.empty?
    raise(
      ArgumentError,
      "Unknown configuration parameters: #{invalid_keys}",
      caller(1)
    )
  end
end