Class: Excalibur::Configuration

Inherits:
Object
  • Object
show all
Includes:
Duplicator
Defined in:
lib/excalibur/configuration.rb

Overview

the Configuration class is responsible for holding the configurable data and logic that will be passed down

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Duplicator

#dup_instance

Constructor Details

#initialize(title = TruncateableContent.new, description = TruncateableContent.new, meta_tags = ::HashWithIndifferentAccess.new({})) ⇒ Configuration

Returns a new instance of Configuration.



11
12
13
14
15
16
17
18
# File 'lib/excalibur/configuration.rb', line 11

def initialize(
    title = TruncateableContent.new,
    description = TruncateableContent.new,
    meta_tags = ::HashWithIndifferentAccess.new({}))
  @title = title
  @description = description
  @meta_tags = meta_tags
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/excalibur/configuration.rb', line 8

def description
  @description
end

#meta_tagsObject

Returns the value of attribute meta_tags.



9
10
11
# File 'lib/excalibur/configuration.rb', line 9

def meta_tags
  @meta_tags
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/excalibur/configuration.rb', line 7

def title
  @title
end

Instance Method Details

#dupObject



33
34
35
36
37
38
# File 'lib/excalibur/configuration.rb', line 33

def dup
  self.class.new(
      dup_instance(@title),
      dup_instance(@description.dup),
      dup_instance(@meta_tags.dup))
end

#merge!(obj) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/excalibur/configuration.rb', line 20

def merge!(obj)
  if obj.is_a? Configuration
    @title = merge_instance(@title, obj.title)
    @description = merge_instance(@description, obj.description)
    @meta_tags = merge_instance(@meta_tags, obj.meta_tags)

    self
  else
    fail(TypeError.new(true),
         'can only merge two Excalibur::Configuration objects')
  end
end

#remove_meta_tag(type, name) ⇒ Object



48
49
50
51
# File 'lib/excalibur/configuration.rb', line 48

def remove_meta_tag(type, name)
  @meta_tags[type].delete(name) if @meta_tags[type].present?
  @meta_tags.delete(type) if @meta_tags[type].empty?
end

#set_meta_tag(type, name, value = nil) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/excalibur/configuration.rb', line 40

def set_meta_tag(type, name, value = nil)
  if @meta_tags[type].nil?
    @meta_tags[type] = ::HashWithIndifferentAccess.new
  end

  @meta_tags[type][name] = value
end