Class: ArticleJSON::Configuration
- Inherits:
-
Object
- Object
- ArticleJSON::Configuration
- Defined in:
- lib/article_json/configuration.rb
Instance Attribute Summary collapse
-
#facebook_token ⇒ Object
Returns the value of attribute facebook_token.
-
#oembed_user_agent ⇒ Object
Returns the value of attribute oembed_user_agent.
Instance Method Summary collapse
-
#element_exporter_for(exporter_type, element_type) ⇒ Class|nil
Get custom exporter class for a given exporter and element type.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#register_element_exporters(exporter, type_class_mapping) ⇒ Object
Register new element exporters or overwrite existing ones for a given exporter type.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
19 20 21 22 23 |
# File 'lib/article_json/configuration.rb', line 19 def initialize @oembed_user_agent = nil @facebook_token = nil @custom_element_exporters = {} end |
Instance Attribute Details
#facebook_token ⇒ Object
Returns the value of attribute facebook_token.
17 18 19 |
# File 'lib/article_json/configuration.rb', line 17 def facebook_token @facebook_token end |
#oembed_user_agent ⇒ Object
Returns the value of attribute oembed_user_agent.
17 18 19 |
# File 'lib/article_json/configuration.rb', line 17 def @oembed_user_agent end |
Instance Method Details
#element_exporter_for(exporter_type, element_type) ⇒ Class|nil
Get custom exporter class for a given exporter and element type
55 56 57 |
# File 'lib/article_json/configuration.rb', line 55 def element_exporter_for(exporter_type, element_type) @custom_element_exporters.dig(exporter_type, element_type) end |
#register_element_exporters(exporter, type_class_mapping) ⇒ Object
Register new element exporters or overwrite existing ones for a given exporter type. Usage example:
register_element_exporters(:html,
image: MyImageExporter,
advertisement: MyAdExporter)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/article_json/configuration.rb', line 33 def register_element_exporters(exporter, type_class_mapping) valid_exporters = %i(html amp facebook_instant_article plain_text) unless valid_exporters.include?(exporter) raise ArgumentError, '`exporter` needs to be one of ' \ "#{valid_exporters} but is `#{exporter.inspect}`" end if !type_class_mapping.is_a?(Hash) || type_class_mapping.keys.any? { |key| !key.is_a? Symbol } || type_class_mapping.values.any? { |value| !value.is_a? Class } raise ArgumentError, '`type_class_mapping` has to be a Hash with '\ 'symbolized keys and classes as values but is '\ "`#{type_class_mapping.inspect}`" end @custom_element_exporters[exporter.to_sym] ||= {} @custom_element_exporters[exporter.to_sym].merge!(type_class_mapping) end |