Class: InertiaRails::MetaTagBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/inertia_rails/meta_tag_builder.rb

Instance Method Summary collapse

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(meta_tag)
  if meta_tag.is_a?(Array)
    meta_tag.each { |tag| add(tag) }
  elsif meta_tag.is_a?(Hash)
    add_new_tag(meta_tag)
  else
    raise ArgumentError, 'Meta tag must be a Hash or Array of Hashes'
  end

  self
end

#clearObject



39
40
41
42
43
# File 'lib/inertia_rails/meta_tag_builder.rb', line 39

def clear
  @meta_tags.clear

  self
end

#meta_tagsObject



10
11
12
# File 'lib/inertia_rails/meta_tag_builder.rb', line 10

def meta_tags
  @meta_tags.values
end

#remove(head_key = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


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