lipa 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/NEWS.md CHANGED
@@ -1,3 +1,59 @@
1
- Release-0.1.0
2
- ---------------------
3
- Initial relese!
1
+ 2011-10-17 Release-0.2.0
2
+ ------------------------
3
+ - New clear API with one general class ```Lipa::Node```. Classes ```Lipa::Leaf``` and ```Lipa::Branch```
4
+ is deprecated and is deleting in release 0.3.0.
5
+
6
+
7
+ ```Ruby
8
+ node :node_1 do
9
+ node :node_2 do
10
+ param_1 :some_value
11
+ end
12
+ end
13
+ ```
14
+
15
+ - Added new methods access to nodes;
16
+
17
+ ```Ruby
18
+ Tree["tree://path/to/obj"]
19
+ tree.path.to.obj
20
+ ```
21
+
22
+ - Extended template functional. For example, if you set attr ```:for => :node``` in kind
23
+ you will use name of kind instead of method ```node``` for subsribtion. [See examples](https://github.com/flipback/lipa/tree/master/examples)
24
+
25
+ ```Ruby
26
+ kind :planet_system, :for => :node do
27
+ num_planet 0
28
+ end
29
+
30
+ kind :planet, :for => :node do
31
+ has_live false
32
+ has_water false
33
+ number 0
34
+ end
35
+
36
+ planet_system :sun_system do
37
+ planet :mercury do
38
+ number 1
39
+ radius 46_001_210
40
+ end
41
+
42
+ planet :venus do
43
+ number 2
44
+ radius 107_476_259
45
+ end
46
+
47
+ planet :earth do
48
+ number 3
49
+ radius 147_098_074
50
+ has_live true
51
+ has_water true
52
+
53
+ node :moon, :radius => 363_104
54
+ end
55
+ end
56
+ ```
57
+ 2011-10-16 Release-0.1.0
58
+ ------------------------
59
+ Initial released!
data/README.md CHANGED
@@ -14,27 +14,32 @@ Installation
14
14
 
15
15
  Example
16
16
  ------------------------------------------------------
17
- ```Ruby
18
- require 'lipa'
19
-
20
- tree = Lipa::Tree.new :tree do
21
- kind :red_leaf do
22
- color "red"
23
- end
24
-
25
- branch :branch do
26
- bunch :color => "green", do
27
- leaf :leaf_green
28
- leaf :leaf_yelow, :color => "yelow"
29
- end
17
+ ```Ruby
18
+ require 'lipa'
19
+
20
+ tree = Lipa::Tree.new :tree do
21
+ kind :red, :for => :node do
22
+ color "red"
23
+ end
24
+
25
+ node :branch do
26
+ with :color => "green", do
27
+ node :leaf_green
28
+ node :leaf_yelow, :color => "yelow"
29
+ end
30
+ end
31
+
32
+ red :red_leaf
30
33
  end
31
34
 
32
- leaf :red_leaf, :kind => :red_leaf
33
- end
34
-
35
-
36
- puts tree["branch/leaf_green"].color
37
- puts tree["branch/leaf_yelow"].color
38
- puts tree["red_leaf"].color
39
- ```
40
-
35
+ #Access
36
+ puts Lipa::Tree["tree://branch/leaf_green"].color
37
+ #or
38
+ puts tree["branch/leaf_yelow"].color
39
+ #or
40
+ puts tree.red_leaf.color
41
+ ```
42
+
43
+ Reference
44
+ ----------------------------------
45
+ Home page: http://lipa.flipback.net
@@ -0,0 +1,24 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'../lib')
2
+ require 'lipa'
3
+
4
+ tree = Lipa::Tree.new :tree do
5
+ kind :red, :for => :node do
6
+ color "red"
7
+ end
8
+
9
+ node :branch do
10
+ with :color => "green", do
11
+ node :leaf_green
12
+ node :leaf_yelow, :color => "yelow"
13
+ end
14
+ end
15
+
16
+ red :red_leaf
17
+ end
18
+
19
+ #Access
20
+ puts Lipa::Tree["tree://branch/leaf_green"].color
21
+ #or
22
+ puts tree["branch/leaf_yelow"].color
23
+ #or
24
+ puts tree.red_leaf.color
@@ -0,0 +1,42 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'../lib')
2
+ require 'lipa'
3
+
4
+ un = Lipa::Tree.new :universe do
5
+ kind :planet_system, :for => :node do
6
+ num_planet 0
7
+ end
8
+
9
+ kind :planet, :for => :node do
10
+ has_live false
11
+ has_water false
12
+ number 0
13
+ end
14
+
15
+ planet_system :sun_system do
16
+ planet :mercury do
17
+ number 1
18
+ radius 46_001_210
19
+ end
20
+
21
+ planet :venus do
22
+ number 2
23
+ radius 107_476_259
24
+ end
25
+
26
+ planet :earth do
27
+ number 3
28
+ radius 147_098_074
29
+ has_live true
30
+ has_water true
31
+
32
+ node :moon, :radius => 363_104
33
+ end
34
+ end
35
+ end
36
+
37
+
38
+ puts un.sun_system.earth.number
39
+ puts un.sun_system.earth.radius
40
+ puts un.sun_system.earth.has_live
41
+ puts un.sun_system.earth.has_water
42
+ puts un.sun_system.earth.moon.radius
data/lib/lipa.rb CHANGED
@@ -24,6 +24,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
24
  =end
25
25
 
26
26
  require "lipa/version"
27
+ require "lipa/node"
27
28
  require "lipa/leaf"
28
29
  require "lipa/branch"
29
30
  require "lipa/bunch"
data/lib/lipa/branch.rb CHANGED
@@ -24,70 +24,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
24
  =end
25
25
 
26
26
  module Lipa
27
- # Implemenation of branch (conteiner) for description
28
- #
29
- # @example
30
- #
31
- # tree = Lipa::Tree.new :tree do
32
- # branch :group_1 do
33
- # leaf :obj_1, :param_1 => "some_param"
34
- # end
35
- # end
36
- # tree["group_1/obj_1"].param_1 #=> "some_param"
37
- #
38
- # alias #branch is #group, #dir
39
-
40
- class Branch < Leaf
27
+ # Deprecte class
28
+ # Don't use it
29
+ class Branch < Node
41
30
  init_methods :branch, :dir, :group
42
-
43
- def method_missing(name, *args, &block)
44
- @attrs[:leafs] ||= {}
45
- init_class = @@init_methods[name.to_s]
46
- if init_class
47
- args[1] ||= {}
48
- args[1][:branch] = self
49
- @attrs[:leafs][args[0].to_s] = init_class.send(:new, *args, &block )
50
- else
51
- super
52
- end
53
- end
54
-
55
- # Accessor for entry by path
56
- # @param [String] path to entry
57
- # @return entry
58
- #
59
- # @example
60
- # tree["dir_1/dir_2/searched_obj"]
61
- def [](path)
62
- split_path = path.split("/")
63
- obj = @attrs[:leafs][split_path[0]]
64
- if obj
65
- if split_path.size > 1
66
- obj[split_path[1..-1].join("/")]
67
- else
68
- obj
69
- end
70
- end
31
+ def initialize(name, attrs = {}, &block)
32
+ warn "#{__FILE__}:#{__LINE__} Deprecated class. Please use Lipa::Node. It is removing in 0.3.0 version"
33
+ super
71
34
  end
72
-
73
- # Initial method for group description
74
- #
75
- # @example
76
- # tree = Lipa::Tree.new :tree do
77
- # bunch :param_1 => "some_param" do
78
- # leaf :obj_1
79
- # leaf :obj_2
80
- # end
81
- # end
82
- #
83
- # tree["obj_1"].param_1 #=> "some_param"
84
- # tree["obj_2"].param_1 #=> "some_param"
85
- def bunch(attrs = {}, &block)
86
- if block_given?
87
- Lipa::Bunch.new(self, attrs, &block)
88
- end
89
- end
90
-
91
- alias_method :with, :bunch
92
35
  end
93
36
  end
data/lib/lipa/bunch.rb CHANGED
@@ -27,31 +27,31 @@ module Lipa
27
27
  # Implementation of group description
28
28
  #
29
29
  # @example
30
- # tree = Lipa::Tree.new :tree do
31
- # bunch :param_1 => "some_param" do
32
- # leaf :obj_1
33
- # leaf :obj_2
30
+ # tree = Lipa::Tree.new :tree do
31
+ # bunch :param_1 => "some_param" do
32
+ # leaf :obj_1
33
+ # leaf :obj_2
34
+ # end
34
35
  # end
35
- # end
36
36
  #
37
- # tree["obj_1"].param_1 #=> "some_param"
38
- # tree["obj_2"].param_1 #=> "some_param"
37
+ # tree["obj_1"].param_1 #=> "some_param"
38
+ # tree["obj_2"].param_1 #=> "some_param"
39
39
  class Bunch
40
- def initialize(branch, attrs = {}, &block)
40
+ def initialize(parent, attrs = {}, &block)
41
41
  @attrs = attrs
42
- @branch = branch
43
- @branch.attrs[:leafs] ||= {}
42
+ @parent = parent
43
+ @parent.attrs[:children] ||= {}
44
44
 
45
45
  instance_eval &block if block_given?
46
46
  end
47
47
 
48
48
  def method_missing(name, *args, &block)
49
- init_class = Lipa::Leaf.init_methods[name.to_s]
49
+ init_class = Lipa::Node.init_methods[name]
50
50
  if init_class and init_class.class == Class
51
51
  args[1] ||= {}
52
52
  args[1] = @attrs.merge(args[1]) #to save local attrs
53
- args[1][:branch] = @branch
54
- @branch.attrs[:leafs][args[0].to_s] = init_class.send(:new, *args, &block )
53
+ args[1][:parent] = @parent
54
+ @parent.attrs[:children][args[0].to_sym] = init_class.send(:new, *args, &block )
55
55
  else
56
56
  super
57
57
  end
data/lib/lipa/kind.rb CHANGED
@@ -28,17 +28,17 @@ module Lipa
28
28
  #
29
29
  # @example
30
30
  #
31
- # tree = Lipa::Tree.new :tree do
32
- # kind :some_kind do
33
- # param1 "some_param"
34
- # end
31
+ # tree = Lipa::Tree.new :tree do
32
+ # kind :some_kind do
33
+ # param1 "some_param"
34
+ # end
35
35
  #
36
- # leaf :some_instance, :kind => :some_kind
37
- # end
38
- # tree["some_instance"].param_1 #=> "some_param"
36
+ # leaf :some_instance, :kind => :some_kind
37
+ # end
38
+ # tree["some_instance"].param_1 #=> "some_param"
39
39
  #
40
- # alias #kind is #template
41
- class Kind < Branch
40
+ # alias #kind is #template
41
+ class Kind < Node
42
42
  end
43
43
  end
44
44
 
data/lib/lipa/leaf.rb CHANGED
@@ -25,65 +25,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
25
 
26
26
 
27
27
  module Lipa
28
- # Base object for all nested object of tree
29
- # It supports initialization
30
- # attributes by constant, variable or Proc object
31
- #
32
- # @example
33
- # tree = Lipa::Tree.new :tree do
34
- # leaf :object, :param_1 => 4 do
35
- # param_2 "some_param"
36
- # param_3 lambda{1+param_3}
37
- # end
38
- # end
39
- # tree["object"].param_1 #=> 4
40
- # tree["object"].param_2 #=> "some_param"
41
- # tree["object"].param_3 #=> 5
42
-
43
- class Leaf
44
- attr_accessor :attrs
45
- @@init_methods = {"leaf" => self, "object" => self}
46
- @@kinds = {}
47
-
28
+ # Deprecte class
29
+ # Don't use it
30
+ class Leaf < Node
31
+ init_methods :leaf, :object
48
32
  def initialize(name, attrs = {}, &block)
49
- @attrs = attrs
50
- @attrs[:name] = name.to_s
51
-
52
- if attrs[:kind]
53
- @kind = @@kinds[attrs[:kind].to_sym]
54
-
55
- @attrs.merge! @kind.attrs
56
- end
57
-
58
- instance_eval &block if block_given?
59
- end
60
-
61
- def method_missing(name, *args, &block)
62
- case args.size
63
- when 0
64
- val = @attrs[name]
65
- if val.class == Proc
66
- val.call
67
- else
68
- val
69
- end
70
- when 1
71
- name = name.to_s
72
- name["="] = "" if name["="]
73
- @attrs[name.to_sym] = args[0]
74
- else
75
- super
76
- end
77
- end
78
-
79
- def self.init_methods(*names)
80
- if names.size > 0
81
- names.each do |name|
82
- @@init_methods[name.to_s] = self
83
- end
84
- else
85
- @@init_methods
86
- end
33
+ warn "#{__FILE__}:#{__LINE__} Deprecated class. Please use Lipa::Node. It is removing in 0.3.0 version"
34
+ super
87
35
  end
88
36
  end
89
37
  end
data/lib/lipa/node.rb ADDED
@@ -0,0 +1,159 @@
1
+ =begin
2
+ Lipa - DSL for description treelike structures in Ruby
3
+
4
+ Copyright (c) 2011 Aleksey Timin
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ 'Software'), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ =end
25
+
26
+
27
+ module Lipa
28
+ # Base object for all nested object of tree
29
+ # It supports initialization
30
+ # attributes by constant, variable or Proc object
31
+ #
32
+ # @example
33
+ # tree = Lipa::Tree.new :tree do
34
+ # node :object, :param_1 => 4 do
35
+ # param_2 "some_param"
36
+ # param_3 lambda{1+param_3}
37
+ # end
38
+ # end
39
+ # tree["object"].param_1 #=> 4
40
+ # tree["object"].param_2 #=> "some_param"
41
+ # tree["object"].param_3 #=> 5
42
+ class Node
43
+ attr_accessor :attrs
44
+ @@init_methods = {:node => self}
45
+ @@kinds = {}
46
+
47
+ def initialize(name, attrs = {}, &block)
48
+ @attrs = {}
49
+ @attrs[:name] = name.to_s
50
+
51
+ #init attrs from template
52
+ if attrs[:kind]
53
+ kind = @@kinds[attrs[:kind].to_sym]
54
+ @attrs.merge! kind.attrs if kind
55
+ end
56
+
57
+ @attrs.merge! attrs
58
+ instance_eval &block if block_given?
59
+ end
60
+
61
+ def method_missing(name, *args, &block)
62
+ @attrs[:children] ||= {}
63
+
64
+ # Init from kind
65
+ kind = @@kinds[name]
66
+ if kind and kind.for
67
+ init_class = @@init_methods[kind.for]
68
+ args[1] ||= {}
69
+ args[1][:kind] = kind.name
70
+ else
71
+ #from init methods
72
+ init_class = @@init_methods[name]
73
+ end
74
+
75
+ if init_class
76
+ # Making children objects
77
+ args[1] ||= {}
78
+ args[1][:parent] = self
79
+ @attrs[:children][args[0].to_sym] = init_class.send(:new, *args, &block )
80
+ else
81
+ case args.size
82
+ when 0
83
+ child = @attrs[:children][name]
84
+ return child if child
85
+
86
+ val = @attrs[name]
87
+ if val.class == Proc
88
+ val.call
89
+ else
90
+ val
91
+ end
92
+ when 1
93
+ name = name.to_s
94
+ name["="] = "" if name["="]
95
+ @attrs[name.to_sym] = args[0]
96
+ else
97
+ super
98
+ end
99
+ end
100
+ end
101
+
102
+ # Accessor for node by path
103
+ # @param [String] path nodes
104
+ # @return [Node] node
105
+ #
106
+ # @example
107
+ # tree["dir_1/dir_2/searched_obj"]
108
+ def [](path)
109
+ split_path = path.split("/")
110
+ obj = @attrs[:children][split_path[0].to_sym]
111
+ if obj
112
+ if split_path.size > 1
113
+ obj[split_path[1..-1].join("/")]
114
+ else
115
+ obj
116
+ end
117
+ end
118
+ end
119
+
120
+ # Initial method for group description
121
+ #
122
+ # @example
123
+ # tree = Lipa::Tree.new :tree do
124
+ # with :param_1 => "some_param" do
125
+ # leaf :obj_1
126
+ # leaf :obj_2
127
+ # end
128
+ # end
129
+ #
130
+ # tree["obj_1"].param_1 #=> "some_param"
131
+ # tree["obj_2"].param_1 #=> "some_param"
132
+ def with(attrs = {}, &block)
133
+ if block_given?
134
+ Lipa::Bunch.new(self, attrs, &block)
135
+ end
136
+ end
137
+
138
+ def self.init_methods(*names)
139
+ if names.size > 0
140
+ names.each do |name|
141
+ @@init_methods[name.to_sym] = self
142
+ end
143
+ else
144
+ @@init_methods
145
+ end
146
+ end
147
+
148
+ #Deprecated methods
149
+ def bunch(attrs = {}, &block)
150
+ warn "#{__FILE__}:#{__LINE__} Deprecated method. Please use Lipa::Node. It is removing in 0.3.0 version"
151
+ with(attrs, &block)
152
+ end
153
+
154
+ def leafs
155
+ warn "#{__FILE__}:#{__LINE__} Deprecated method. Please use Lipa::Node. It is removing in 0.3.0 version"
156
+ attrs[:children]
157
+ end
158
+ end
159
+ end
data/lib/lipa/tree.rb CHANGED
@@ -27,35 +27,48 @@ module Lipa
27
27
  # Implementaion of root of description
28
28
  # @example
29
29
  #
30
- # tree = Lipa::Tree.new :tree do
31
- # leaf :object do
32
- # param_1 "some_param"
33
- # param_2 lambda{1+2}
30
+ # tree = Lipa::Tree.new :tree do
31
+ # leaf :object do
32
+ # param_1 "some_param"
33
+ # param_2 lambda{1+2}
34
+ # end
34
35
  # end
35
- # end
36
36
  #
37
- # tree["object"].param_1 #=> "some_param"
38
- # tree["object"].param_2 #=> 3
39
- class Tree < Branch
40
- attr_reader :kinds
37
+ # tree["object"].param_1 #=> "some_param"
38
+ # tree["object"].param_2 #=> 3
39
+ class Tree < Node
40
+ @@trees = {}
41
+ def initialize(name, attrs = {}, &block_given)
42
+ super
43
+ @@trees.merge! name.to_s => self
44
+ end
41
45
 
42
46
  # Initialize of kind
43
47
  # @see Lipa::Kind
44
48
  #
45
49
  # @example
50
+ # kind :some_kind do
51
+ # param1 "some_param"
52
+ # end
46
53
  #
47
- # kind :some_kind do
48
- # param1 "some_param"
49
- # end
50
- #
51
- # leaf :some_instance, :kind => :some_kind
54
+ # leaf :some_instance, :kind => :some_kind
52
55
  def kind(name, attrs = {}, &block)
53
- if block_given?
54
- @@kinds ||= {}
55
- @@kinds[name.to_sym] = Lipa::Kind.new(name, attrs, &block)
56
- end
56
+ @@kinds ||= {}
57
+ @@kinds[name.to_sym] = Lipa::Kind.new(name, attrs, &block)
57
58
  end
58
59
 
59
60
  alias_method :template, :kind
61
+
62
+ # Accessor for node by uri
63
+ #
64
+ # @param [String] uri by format [tree_name]://[path]
65
+ # @return [Node] node
66
+ #
67
+ # @example
68
+ # Lipa::Tree["some_tree://node_1/node_2"]
69
+ def self.[](uri)
70
+ tree, path = uri.split("://")
71
+ @@trees[tree][path] if @@trees[tree]
72
+ end
60
73
  end
61
74
  end
data/lib/lipa/version.rb CHANGED
@@ -24,5 +24,5 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
24
  =end
25
25
 
26
26
  module Lipa
27
- VERSION = "0.1.0"
27
+ VERSION = "0.2.0"
28
28
  end
data/spec/bunch_spec.rb CHANGED
@@ -14,7 +14,7 @@ describe Lipa::Bunch do
14
14
  it 'should have "with" initial method' do
15
15
  t = Lipa::Tree.new("1") do
16
16
  with :attr_1 => 999 do
17
- leaf :obj_1
17
+ node :obj_1
18
18
  end
19
19
  end
20
20
  t["obj_1"].attr_1.should eql(999)
data/spec/kind_spec.rb CHANGED
@@ -8,4 +8,9 @@ describe Lipa::Kind do
8
8
  it 'should support local changing in instances' do
9
9
  tree["group_3/obj_x"].attr_1.should eql("from_instance")
10
10
  end
11
+
12
+ it 'should create init method with name template' do
13
+ tree.folder_1.some_file.size.should eql(1024)
14
+ tree.folder_1.some_file.ext.should eql("txt")
15
+ end
11
16
  end
data/spec/node_spec.rb ADDED
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe Lipa::Node do
4
+ before :each do
5
+ @node = tree["group_1/obj_1"]
6
+ end
7
+
8
+ it 'should have name' do
9
+ @node.name.should eql("obj_1")
10
+ end
11
+
12
+ it 'should have parent' do
13
+ @node.parent.should eql(tree["group_1"])
14
+ end
15
+
16
+ it 'should have descripted attr_1 eql 5' do
17
+ @node.attr_1.should eql(5)
18
+ end
19
+
20
+ it 'should have descripted attr_2 eql 4' do
21
+ @node.attr_2.should eql(3)
22
+ end
23
+
24
+ it 'should have descripted attr_3 eql sum of attr_1 and attr_2' do
25
+ @node.attr_3.should eql(8)
26
+ end
27
+
28
+ it 'should support write access for attrs' do
29
+ @node.attr_1 = 8
30
+ @node.attr_1.should eql(8)
31
+ end
32
+
33
+ it 'should have hash access for attrs' do
34
+ @node.attrs[:attr_1].should eql(8)
35
+ @node.attrs[:attr_1] = 9
36
+ @node.attrs[:attr_1].should eql(9)
37
+ end
38
+
39
+ it 'should have children' do
40
+ @node.children[:obj_2].should eql(tree["group_1/obj_1/obj_2"])
41
+ @node.children[:obj_3].should eql(tree["group_1/obj_1/obj_3"])
42
+ end
43
+
44
+ it 'should have [] for access entry by path' do
45
+ @node["obj_3"].should eql(tree["group_1/obj_1/obj_3"])
46
+ end
47
+
48
+ it 'should access for children by .' do
49
+ @node.obj_3.should eql(tree["group_1/obj_1/obj_3"])
50
+ end
51
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,39 +1,47 @@
1
1
  require "lipa"
2
2
 
3
3
  TREE ||= Lipa::Tree.new "lipa" do
4
- branch :group_1 do
4
+ node :group_1 do
5
5
  any_attr "any attr"
6
6
 
7
- leaf :obj_1, :attr_1 => 5 do
7
+ node :obj_1, :attr_1 => 5 do
8
8
  attr_2 3
9
9
  attr_3 lambda{attr_1 + attr_2}
10
- end
11
-
12
- leaf :obj_2
13
10
 
14
- branch :group_2 do
15
- leaf :obj_3
11
+ node :obj_2
12
+ node :obj_3
16
13
  end
17
14
  end
18
15
 
19
- bunch :attr_1 => 100, :attr_2 => "attr_2" do
20
- leaf :obj_4
21
- leaf :obj_5
22
- leaf :obj_6, :attr_1 => 200, :attr_2 => ""
16
+ with :attr_1 => 100, :attr_2 => "attr_2" do
17
+ node :obj_4
18
+ node :obj_5
19
+ node :obj_6, :attr_1 => 200, :attr_2 => ""
23
20
  end
24
21
 
22
+ # Template
25
23
  kind :kind_group do
26
- leaf :obj_x
27
- leaf :obj_y do
24
+ node :obj_x
25
+ node :obj_y do
28
26
  attr_1 "from_kind"
29
27
  end
30
28
  end
31
29
 
32
- branch :group_3, :kind => :kind_group do
33
- leaf :obj_x do
30
+ node :group_3, :kind => :kind_group do
31
+ node :obj_x do
34
32
  attr_1 "from_instance"
35
33
  end
36
34
  end
35
+ #or
36
+ kind :folder, :for => :node
37
+ kind :file, :for => :node do
38
+ size 1024
39
+ ext "jpg"
40
+ end
41
+
42
+ folder :folder_1 do
43
+ file :some_file, :ext => "txt"
44
+ end
37
45
  end
38
46
 
39
47
  def tree
data/spec/tree_spec.rb ADDED
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe Lipa::Tree do
4
+ it "should have access any object in trees" do
5
+ Lipa::Tree["lipa://group_1/obj_1"].should eql(tree["group_1/obj_1"])
6
+ end
7
+ end
8
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lipa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-16 00:00:00.000000000Z
12
+ date: 2011-10-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &16006520 !ruby/object:Gem::Requirement
16
+ requirement: &21636340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *16006520
24
+ version_requirements: *21636340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &16005820 !ruby/object:Gem::Requirement
27
+ requirement: &21635780 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *16005820
35
+ version_requirements: *21635780
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &16004980 !ruby/object:Gem::Requirement
38
+ requirement: &21635220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *16004980
46
+ version_requirements: *21635220
47
47
  description:
48
48
  email: atimin@gmail.com
49
49
  executables: []
@@ -55,19 +55,22 @@ files:
55
55
  - lib/lipa.rb
56
56
  - lib/lipa/version.rb
57
57
  - lib/lipa/kind.rb
58
+ - lib/lipa/node.rb
58
59
  - lib/lipa/leaf.rb
59
60
  - lib/lipa/bunch.rb
60
61
  - lib/lipa/tree.rb
61
62
  - lib/lipa/branch.rb
63
+ - spec/tree_spec.rb
64
+ - spec/node_spec.rb
62
65
  - spec/kind_spec.rb
63
66
  - spec/spec_helper.rb
64
- - spec/branch_spec.rb
65
67
  - spec/bunch_spec.rb
66
- - spec/leaf_spec.rb
68
+ - examples/simple_tree.rb
69
+ - examples/universe.rb
67
70
  - Rakefile
68
71
  - README.md
69
72
  - NEWS.md
70
- homepage: http://xpca.org
73
+ homepage: http://lipa.flipback.net
71
74
  licenses: []
72
75
  post_install_message:
73
76
  rdoc_options:
data/spec/branch_spec.rb DELETED
@@ -1,30 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe Lipa::Branch do
4
- before :each do
5
- @grp = tree["group_1"]
6
- end
7
-
8
- it 'should have leafs (children)' do
9
- @grp.leafs["obj_1"].should eql(tree["group_1/obj_1"])
10
- @grp.leafs["obj_2"].should eql(tree["group_1/obj_2"])
11
- end
12
-
13
- it 'should have [] for access entry by path' do
14
- @grp["group_2/obj_3"].should eql(tree["group_1/group_2/obj_3"])
15
- end
16
-
17
- it 'should have any attrs also as leaf (Lipa::Leaf)' do
18
- @grp.any_attr.should eql("any attr")
19
- end
20
-
21
- it 'should have "dir" initial method' do
22
- t = Lipa::Tree.new(nil) { dir :dir_1 }
23
- t["dir_1"].class.should eql(Lipa::Branch)
24
- end
25
-
26
- it 'should have "object" initial method' do
27
- t = Lipa::Tree.new(nil) { group :group_1 }
28
- t["group_1"].class.should eql(Lipa::Branch)
29
- end
30
- end
data/spec/leaf_spec.rb DELETED
@@ -1,43 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe Lipa::Leaf do
4
- before :each do
5
- @obj = tree["group_1/obj_1"]
6
- end
7
-
8
- it 'should have name' do
9
- @obj.name.should eql("obj_1")
10
- end
11
-
12
- it 'should have branch (parent)' do
13
- @obj.branch.should eql(tree["group_1"])
14
- end
15
-
16
- it 'should have descripted attr_1 eql 5' do
17
- @obj.attr_1.should eql(5)
18
- end
19
-
20
- it 'should have descripted attr_2 eql 4' do
21
- @obj.attr_2.should eql(3)
22
- end
23
-
24
- it 'should have descripted attr_3 eql sum of attr_1 and attr_2' do
25
- @obj.attr_3.should eql(8)
26
- end
27
-
28
- it 'should support write access for attrs' do
29
- @obj.attr_1 = 8
30
- @obj.attr_1.should eql(8)
31
- end
32
-
33
- it 'should have hash access for attrs' do
34
- @obj.attrs[:attr_1].should eql(8)
35
- @obj.attrs[:attr_1] = 9
36
- @obj.attrs[:attr_1].should eql(9)
37
- end
38
-
39
- it 'should have "object" initial method' do
40
- t = Lipa::Tree.new(nil) { object :obj }
41
- t["obj"].class.should eql(Lipa::Leaf)
42
- end
43
- end