Class: Lipa::Root

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

Overview

Implementaion of root of description

Examples:


tree = Lipa::Root.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, #children, #full_name, #name, #parent, #root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

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

Constructor Details

#initialize(name, &block) ⇒ Root

Returns a new instance of Root.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lipa/root.rb', line 42

def initialize(name, &block)
  @kinds = {}
  @root = self
  @children = {}
  @attrs = {}
  @name = "/"
  @full_name = "/"

  instance_eval &block if block_given?

  @@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/root.rb', line 40

def kinds
  @kinds
end

Class Method Details

.[](uri) ⇒ Node

Accessor for node by uri

Examples:

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

Parameters:

Returns:



77
78
79
80
# File 'lib/lipa/root.rb', line 77

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:



64
65
66
# File 'lib/lipa/root.rb', line 64

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

#load_from(path) ⇒ Object

Load description tree from file

Examples:

root "lipa" do
  load_from File.dirname(__FILE__) + "/data/part_of_tree.rb"
end

Parameters:

  • path

    to file



90
91
92
93
94
# File 'lib/lipa/root.rb', line 90

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