Class: InertiaRails::MetaTagBuilder
- Inherits:
-
Object
- Object
- InertiaRails::MetaTagBuilder
- Defined in:
- lib/inertia_rails/meta_tag_builder.rb
Instance Method Summary collapse
- #add(meta_tag) ⇒ Object
- #clear ⇒ Object
-
#initialize(controller) ⇒ MetaTagBuilder
constructor
A new instance of MetaTagBuilder.
- #meta_tags ⇒ Object
- #remove(head_key = nil, &block) ⇒ Object
Constructor Details
#initialize(controller) ⇒ MetaTagBuilder
Returns a new instance of MetaTagBuilder.
5 6 7 8 |
# File 'lib/inertia_rails/meta_tag_builder.rb', line 5 def initialize(controller) @controller = controller @meta_tags = {} end |
Instance Method Details
#add(meta_tag) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/inertia_rails/meta_tag_builder.rb', line 14 def add() if .is_a?(Array) .each { |tag| add(tag) } elsif .is_a?(Hash) add_new_tag() else raise ArgumentError, 'Meta tag must be a Hash or Array of Hashes' end self end |
#clear ⇒ Object
39 40 41 42 43 |
# File 'lib/inertia_rails/meta_tag_builder.rb', line 39 def clear @meta_tags.clear self end |
#meta_tags ⇒ Object
10 11 12 |
# File 'lib/inertia_rails/meta_tag_builder.rb', line 10 def @meta_tags.values end |
#remove(head_key = nil, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/inertia_rails/meta_tag_builder.rb', line 26 def remove(head_key = nil, &block) raise ArgumentError, 'Cannot provide both head_key and a block' if head_key && block_given? raise ArgumentError, 'Must provide either head_key or a block' if head_key.nil? && !block_given? if head_key @meta_tags.delete(head_key) else @meta_tags.reject! { |_, tag| block.call(tag) } end self end |