Class: AngryMob::Node

Inherits:
Struct
  • Object
show all
Includes:
Log
Defined in:
lib/angry_mob/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

#__class_to_s, #__class_to_s!, #debug, #log

Constructor Details

#initialize(name, attributes) ⇒ Node

Returns a new instance of Node.



5
6
7
8
# File 'lib/angry_mob/node.rb', line 5

def initialize(name, attributes)
  self.name = name
  self.attributes = AngryHash[attributes]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



40
41
42
# File 'lib/angry_mob/node.rb', line 40

def method_missing(method,*args,&block)
  attributes.__send__(method,*args)
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes

Returns:

  • (Object)

    the current value of attributes



2
3
4
# File 'lib/angry_mob/node.rb', line 2

def attributes
  @attributes
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/angry_mob/node.rb', line 2

def name
  @name
end

#resource_locatorObject

Returns the value of attribute resource_locator

Returns:

  • (Object)

    the current value of resource_locator



2
3
4
# File 'lib/angry_mob/node.rb', line 2

def resource_locator
  @resource_locator
end

Instance Method Details

#__consolidate_hash(hash, seen) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/angry_mob/node.rb', line 25

def __consolidate_hash(hash,seen)

  return if seen.key?(hash)
  seen[hash] = true

  hash.each do |key,value|
    case value
    when Hash
      __consolidate_hash(value,seen)
    when Proc
      hash[key] = value[self]
    end
  end
end

#consolidate!Object



19
20
21
22
# File 'lib/angry_mob/node.rb', line 19

def consolidate!
  node = self
  __consolidate_hash(attributes,{})
end

#merge_defaults!(attrs) ⇒ Object



10
11
12
13
# File 'lib/angry_mob/node.rb', line 10

def merge_defaults!(attrs)
  puts "merging defaults"
  attributes.reverse_deep_merge!(attrs)
end

#setup_finished!Object



15
16
17
# File 'lib/angry_mob/node.rb', line 15

def setup_finished!
  self.resource_locator ||= AngryMob::Target::DefaultResourceLocator.new
end