/usr/lib/ruby/vendor_ruby/roadie/rails/options.rb is in ruby-roadie-rails 1.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | module Roadie
module Rails
class Options
ATTRIBUTE_NAMES = [
:after_transformation,
:asset_providers,
:before_transformation,
:external_asset_providers,
:keep_uninlinable_css,
:url_options,
]
private_constant :ATTRIBUTE_NAMES
attr_reader(*ATTRIBUTE_NAMES)
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
def url_options=(options)
@url_options = options
end
def before_transformation=(callback)
@before_transformation = callback
end
def after_transformation=(callback)
@after_transformation = callback
end
def keep_uninlinable_css=(bool)
@keep_uninlinable_css = bool
end
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
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
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
def merge(options)
dup.merge! options
end
def merge!(options)
ATTRIBUTE_NAMES.each do |attribute|
send "#{attribute}=", options.fetch(attribute, send(attribute))
end
self
end
def combine(options)
dup.combine! options
end
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
private
def combine_hash(first, second)
combine_nilable(first, second) do |a, b|
a.merge(b)
end
end
def combine_callable(first, second)
combine_nilable(first, second) do |a, b|
proc { |*args| a.call(*args); b.call(*args) }
end
end
def combine_providers(first, second)
combine_nilable(first, second) do |a, b|
ProviderList.new(a.to_a + Array.wrap(b))
end
end
def combine_nilable(first, second)
if first && second
yield first, second
else
first ? first : second
end
end
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
end
end
end
|