Class: Mantra::Manifest::LeafElement

Inherits:
Element
  • Object
show all
Defined in:
lib/mantra/manifest/leaf_element.rb

Instance Attribute Summary

Attributes inherited from Element

#content, #parent

Instance Method Summary collapse

Methods inherited from Element

#array_selector?, #can_merge?, create, #delete, element_with_selector, #escape_root, #fetch, #find, #get, #has_equal_name?, #has_name?, #hash_selector?, #initialize, #match_selector?, #merge_conflict_error, #method_missing, #name, #path, #path_exist?, #respond_to_missing?, #selector, #split_selector

Methods included from Helpers::RegexpHelper

#to_regexp

Methods included from Helpers::ObjectWithType

included

Constructor Details

This class inherits a constructor from Mantra::Manifest::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mantra::Manifest::Element

Instance Method Details

#add_node(selector, value) ⇒ Object

Raises:



29
30
31
32
# File 'lib/mantra/manifest/leaf_element.rb', line 29

def add_node(selector, value)
  raise UnknownScopeError.new("Can't add nodes to leaf")  unless selector.empty?
  raise MergeConflictError.new("Leaf already exists with another value: #{self.content} != #{value}") unless self.content != value
end

#childrenObject



34
35
36
# File 'lib/mantra/manifest/leaf_element.rb', line 34

def children
  []
end

#content=(content) ⇒ Object



7
8
9
# File 'lib/mantra/manifest/leaf_element.rb', line 7

def content=(content)
  @content = content
end

#merge(element, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/mantra/manifest/leaf_element.rb', line 11

def merge(element, options={})
  element = escape_root(element)
  raise merge_conflict_error(element) unless self.can_merge?(element)
  if !options[:force]
    raise MergeConflictError.new("value conflict detected: #{self.content} != #{element.content}") if self.content != element.content
  end
  self.content = element.content
  self
end

#to_ruby_objectObject



21
22
23
# File 'lib/mantra/manifest/leaf_element.rb', line 21

def to_ruby_object
  self.content
end

#traverse(&block) ⇒ Object



25
26
27
# File 'lib/mantra/manifest/leaf_element.rb', line 25

def traverse(&block)
  block.call(self)
end