class Excalibur::Configuration

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

Attributes

description[RW]
meta_tags[RW]
title[RW]

Public Class Methods

new( title = TruncateableContent.new, description = TruncateableContent.new, meta_tags = ::HashWithIndifferentAccess.new({})) click to toggle source
# 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

Public Instance Methods

dup() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

merge_content(old, new) click to toggle source
# File lib/excalibur/configuration.rb, line 65
def merge_content(old, new)
  if old.is_a? ::Hash
    old.deep_merge!(new)
  elsif old.is_a? TruncateableContent
    old.merge!(new)
  elsif old.is_a? ::String
    old + new
  else
    new
  end
end
merge_instance(old, new) click to toggle source
# File lib/excalibur/configuration.rb, line 55
def merge_instance(old, new)
  if old.is_a? new.class
    merge_content(old, new)
  elsif !new.nil?
    new
  else
    old
  end
end