Class: Lipa::Tree
Overview
Implementaion of root of description
Constant Summary collapse
- @@trees =
{}
Instance Attribute Summary collapse
-
#kinds ⇒ Object
readonly
Returns the value of attribute kinds.
Attributes inherited from Node
Class Method Summary collapse
-
.[](uri) ⇒ Node
Accessor for node by uri.
Instance Method Summary collapse
-
#initialize(name, attrs = {}, &block_given) ⇒ Tree
constructor
A new instance of Tree.
-
#kind(name, attrs = {}, &block) ⇒ Object
(also: #template)
Initialize of kind.
-
#load_from(path) ⇒ Object
Load description tree from file.
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
#kinds ⇒ Object (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
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
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
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 |