Class: ArticleJSON::Configuration
- Inherits:
-
Object
- Object
- ArticleJSON::Configuration
- Defined in:
- lib/article_json/configuration.rb
Instance Attribute Summary collapse
-
#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.
-
#html_element_exporters ⇒ Hash[Symbol => Class]
deprecated
Deprecated.
use ‘#exporter_for` instead
-
#html_element_exporters=(value) ⇒ Object
deprecated
Deprecated.
use ‘#register_element_exporters(:html, …)` instead
-
#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.
-
#register_html_element_exporter(type, klass) ⇒ Object
deprecated
Deprecated.
Use ‘#register_element_exporters_for(:html, …)` instead
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
19 20 21 22 |
# File 'lib/article_json/configuration.rb', line 19 def initialize = nil @custom_element_exporters = {} end |
Instance Attribute Details
#oembed_user_agent ⇒ Object
Returns the value of attribute oembed_user_agent.
17 18 19 |
# File 'lib/article_json/configuration.rb', line 17 def end |
Instance Method Details
#element_exporter_for(exporter_type, element_type) ⇒ Class|nil
Get custom exporter class for a given exporter and element type
75 76 77 |
# File 'lib/article_json/configuration.rb', line 75 def element_exporter_for(exporter_type, element_type) @custom_element_exporters.dig(exporter_type, element_type) end |
#html_element_exporters ⇒ Hash[Symbol => Class]
use ‘#exporter_for` instead
Return custom HTML exporters
35 36 37 |
# File 'lib/article_json/configuration.rb', line 35 def html_element_exporters @custom_element_exporters[:html] || {} end |
#html_element_exporters=(value) ⇒ Object
use ‘#register_element_exporters(:html, …)` instead
Set custom HTML exporters
42 43 44 |
# File 'lib/article_json/configuration.rb', line 42 def html_element_exporters=(value) @custom_element_exporters[:html] = value 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)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/article_json/configuration.rb', line 54 def register_element_exporters(exporter, type_class_mapping) unless i(html amp).include?(exporter) raise ArgumentError, '`exporter` needs to be either `:html` or `:amp` '\ "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 |
#register_html_element_exporter(type, klass) ⇒ Object
Use ‘#register_element_exporters_for(:html, …)` instead
Register a new HTML element exporter or overwrite existing ones.
28 29 30 |
# File 'lib/article_json/configuration.rb', line 28 def register_html_element_exporter(type, klass) register_element_exporters(:html, type => klass) end |