Class: Lipa::Tree

Inherits:
Node
  • Object
show all
Defined in:
lib/lipa/tree.rb

Overview

Implementaion of root of description

Examples:


tree = Lipa::Tree.new :tree do 
  node :object do
    param_1 "some_param"
    param_2 run{param_1 + "!!!!"}
  end
end

tree.object.param_1 #=> "some_param"
tree.object.param_2 #=> "some_param!!!!"

Constant Summary collapse

@@trees =
{}

Instance Attribute Summary collapse

Attributes inherited from Node

#attrs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#[], add_node, init_methods, #method_missing, #ref, #run, #with

Constructor Details

#initialize(name, attrs = {}, &block_given) ⇒ Tree

Returns a new instance of Tree.



42
43
44
45
46
47
# File 'lib/lipa/tree.rb', line 42

def initialize(name, attrs = {}, &block_given)
  @kinds = {}
  attrs[:tree] = self
  super
  @@trees.merge! name.to_s => self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Lipa::Node

Instance Attribute Details

#kindsObject (readonly)

Returns the value of attribute kinds.



40
41
42
# File 'lib/lipa/tree.rb', line 40

def kinds
  @kinds
end

Class Method Details

.[](uri) ⇒ Node

Accessor for node by uri

Examples:

Lipa::Tree["some_tree://node_1/node_2"] 

Parameters:

Returns:



72
73
74
75
# File 'lib/lipa/tree.rb', line 72

def self.[](uri)
  tree, path = uri.split("://")
  @@trees[tree][path] if @@trees[tree] 
end

Instance Method Details

#kind(name, attrs = {}, &block) ⇒ Object Also known as: template

Initialize of kind

Examples:

kind :some_kind do
  param1 "some_param"
end

some_kind :some_instance 

See Also:



58
59
60
61
# File 'lib/lipa/tree.rb', line 58

def kind(name, attrs = {}, &block)
  attrs = { :tree => self }
  @kinds[name.to_sym] = Lipa::Kind.new(name, attrs, &block)
end

#load_from(path) ⇒ Object

Load description tree from file

Examples:

Lipa::Tree.new "lipa" do
  load_from File.dirname(__FILE__) + "/data/part_of_tree.rb"
end

Parameters:

  • path

    to file



85
86
87
88
89
# File 'lib/lipa/tree.rb', line 85

def load_from(path)
  File.open(path,'r') do |f|
    instance_eval f.read
  end
end