lipa 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.md +28 -0
- data/README.md +5 -2
- data/examples/simple_tree.rb +4 -4
- data/examples/store.rb +1 -1
- data/examples/universe.rb +1 -1
- data/lib/lipa.rb +5 -1
- data/lib/lipa/bunch.rb +2 -3
- data/lib/lipa/kind.rb +3 -8
- data/lib/lipa/node.rb +75 -44
- data/lib/lipa/{tree.rb → root.rb} +13 -8
- data/lib/lipa/version.rb +1 -1
- data/spec/access_by_path_spec.rb +9 -1
- data/spec/bunch_spec.rb +3 -3
- data/spec/kind_spec.rb +5 -1
- data/spec/{node_spec.rb → node_attrs_spec.rb} +18 -31
- data/spec/node_vars_spec.rb +56 -0
- data/spec/{tree_spec.rb → root_spec.rb} +20 -3
- metadata +37 -24
data/NEWS.md
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
2011-11-05 Release-1.0.0
|
2
|
+
----------------------
|
3
|
+
- Added method Node#eval_attrs to access to attrs node with eval
|
4
|
+
|
5
|
+
```Ruby
|
6
|
+
node :some_node d:
|
7
|
+
param_1 1
|
8
|
+
param_2 run{ param_1 + 2}
|
9
|
+
end
|
10
|
+
|
11
|
+
node.attrs #=> {:param_1 => 1, :param_2 => Proc}
|
12
|
+
node.eval_attrs #=> {:param_1 => 1, :param_2 => 3}
|
13
|
+
```
|
14
|
+
|
15
|
+
- Renamed Lipa::Tree -> Lipa::Root and added helper method for initialization
|
16
|
+
|
17
|
+
```Ruby
|
18
|
+
tree = root :tree do
|
19
|
+
node :node_1
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
- Fixed bug in Lipa::Node. Attributes is working with false values.
|
24
|
+
- Added :full_name attribute to Lipa::Node
|
25
|
+
- Attributes :name, :parent, :children, :root, :full_name, :kind are instance variables
|
26
|
+
- Fixed bug for calls: `node[""] #=> self` and `node["/"] #=> tree`
|
27
|
+
- All instances of Lipa::Tree have name an full name equal "/"
|
28
|
+
|
1
29
|
2011-10-27 Release-0.3.0
|
2
30
|
-----------------------
|
3
31
|
- Added supporting references to other object as attribute ```Node#ref```
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
Lipa -
|
1
|
+
Lipa [![Build Status](https://secure.travis-ci.org/flipback/lipa.png)](http://travis-ci.org/flipback/lipa)
|
2
2
|
=======================================================
|
3
3
|
|
4
|
+
Lipa - DSL for description treelike structures in Ruby
|
5
|
+
|
4
6
|
Features
|
5
7
|
------------------------------------------------------
|
6
8
|
- Creating treelike structures for Ruby in DSL style
|
@@ -16,7 +18,7 @@ Example
|
|
16
18
|
------------------------------------------------------
|
17
19
|
|
18
20
|
require 'lipa'
|
19
|
-
un =
|
21
|
+
un = root :universe do
|
20
22
|
kind :planet_system do
|
21
23
|
num_planet run{
|
22
24
|
count = 0
|
@@ -61,3 +63,4 @@ Example
|
|
61
63
|
Reference
|
62
64
|
----------------------------------
|
63
65
|
Home page: http://lipa.flipback.net
|
66
|
+
Web access to Lipa https://github.com/flipback/lipa-web
|
data/examples/simple_tree.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
$:.unshift File.join(File.dirname(__FILE__),'../lib')
|
2
2
|
require 'lipa'
|
3
3
|
|
4
|
-
tree =
|
4
|
+
tree = root :tree do
|
5
5
|
kind :red do
|
6
6
|
color "red"
|
7
7
|
end
|
8
8
|
|
9
9
|
node :branch do
|
10
|
-
with :color => "green"
|
10
|
+
with :color => "green" do
|
11
11
|
node :leaf_green
|
12
12
|
node :leaf_yelow, :color => "yelow"
|
13
13
|
end
|
@@ -17,8 +17,8 @@ tree = Lipa::Tree.new :tree do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
#Access
|
20
|
-
puts Lipa::
|
20
|
+
puts Lipa::Root["tree://branch/leaf_green"].color
|
21
21
|
#or
|
22
|
-
puts tree["branch/leaf_yelow"].color
|
22
|
+
puts tree["/branch/leaf_yelow"].color
|
23
23
|
#or
|
24
24
|
puts tree.red_leaf.color
|
data/examples/store.rb
CHANGED
data/examples/universe.rb
CHANGED
data/lib/lipa.rb
CHANGED
data/lib/lipa/bunch.rb
CHANGED
@@ -27,7 +27,7 @@ module Lipa
|
|
27
27
|
# Implementation of group description
|
28
28
|
#
|
29
29
|
# @example
|
30
|
-
# tree =
|
30
|
+
# tree = root :tree do
|
31
31
|
# bunch :param_1 => "some_param" do
|
32
32
|
# leaf :obj_1
|
33
33
|
# leaf :obj_2
|
@@ -45,8 +45,7 @@ module Lipa
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def method_missing(name, *args, &block)
|
48
|
-
args[1]
|
49
|
-
args[1] = @attrs.merge(args[1])
|
48
|
+
args[1] = @attrs.merge(args[1] || {})
|
50
49
|
unless Node.add_node(name, @parent, *args, &block)
|
51
50
|
super
|
52
51
|
end
|
data/lib/lipa/kind.rb
CHANGED
@@ -27,7 +27,7 @@ module Lipa
|
|
27
27
|
# Implemenation of kind(template) for description
|
28
28
|
#
|
29
29
|
# @example
|
30
|
-
# tree =
|
30
|
+
# tree = root :tree do
|
31
31
|
# kind :some_kind do
|
32
32
|
# param1 "some_param"
|
33
33
|
# end
|
@@ -40,13 +40,8 @@ module Lipa
|
|
40
40
|
class Kind
|
41
41
|
attr_reader :attrs, :name, :for, :block
|
42
42
|
def initialize(name, attrs = {}, &block)
|
43
|
-
|
44
|
-
|
45
|
-
@for = attr[:for]
|
46
|
-
attrs[:for] = nil
|
47
|
-
else
|
48
|
-
@for = :node
|
49
|
-
end
|
43
|
+
@for = attrs.delete(:for)
|
44
|
+
@for ||= :node
|
50
45
|
|
51
46
|
@attrs = attrs
|
52
47
|
@name = name.to_sym
|
data/lib/lipa/node.rb
CHANGED
@@ -30,7 +30,7 @@ module Lipa
|
|
30
30
|
# attributes by constant, variable or code
|
31
31
|
#
|
32
32
|
# @example
|
33
|
-
# tree =
|
33
|
+
# tree = root :tree do
|
34
34
|
# node :object, :param_1 => 4 do
|
35
35
|
# param_2 "some_param"
|
36
36
|
# param_3 run{1+param_3}
|
@@ -40,13 +40,18 @@ module Lipa
|
|
40
40
|
# tree.object.param_2 #=> "some_param"
|
41
41
|
# tree.object.param_3 #=> 5
|
42
42
|
class Node
|
43
|
-
attr_accessor :attrs
|
43
|
+
attr_accessor :attrs, :name, :children, :root, :parent, :full_name, :kind
|
44
44
|
@@init_methods = {:node => self}
|
45
45
|
|
46
46
|
def initialize(name, attrs = {}, &block)
|
47
|
+
@name = name.to_s
|
48
|
+
@children = {}
|
49
|
+
@parent = attrs.delete(:parent)
|
50
|
+
@root = attrs.delete(:root)
|
51
|
+
@full_name = attrs.delete(:full_name)
|
52
|
+
@kind = attrs.delete(:kind)
|
47
53
|
@attrs = attrs
|
48
|
-
|
49
|
-
@attrs[:children] ||= {}
|
54
|
+
|
50
55
|
instance_eval &block if block_given?
|
51
56
|
end
|
52
57
|
|
@@ -54,11 +59,13 @@ module Lipa
|
|
54
59
|
unless Node.add_node(name, self, *args, &block)
|
55
60
|
case args.size
|
56
61
|
when 0
|
57
|
-
child =
|
62
|
+
child = children[name]
|
58
63
|
return child if child
|
59
64
|
|
60
65
|
val = @attrs[name]
|
61
|
-
|
66
|
+
|
67
|
+
super if val.nil? #Raise MethodError if don't have it
|
68
|
+
|
62
69
|
if val.class == Proc
|
63
70
|
instance_eval &(val)
|
64
71
|
else
|
@@ -74,6 +81,26 @@ module Lipa
|
|
74
81
|
end
|
75
82
|
end
|
76
83
|
|
84
|
+
# Copy attributes with eval
|
85
|
+
#
|
86
|
+
# @retun [Hash] hash
|
87
|
+
#
|
88
|
+
# @example
|
89
|
+
# node :some_node d:
|
90
|
+
# param_1 1
|
91
|
+
# param_2 run{ param_1 + 2}
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# node.attrs #=> {:param_1 => 1, :param_2 => Proc}
|
95
|
+
# node.eval_attrs #=> {:param_1 => 1, :param_2 => 3}
|
96
|
+
def eval_attrs
|
97
|
+
result = {}
|
98
|
+
@attrs.each_pair do |k,v|
|
99
|
+
result[k.to_sym] = instance_eval(k.to_s)
|
100
|
+
end
|
101
|
+
result
|
102
|
+
end
|
103
|
+
|
77
104
|
# Accessor for node by path in Unix style
|
78
105
|
# @param [String] path nodes
|
79
106
|
# @return [Node] node
|
@@ -84,31 +111,36 @@ module Lipa
|
|
84
111
|
# dir_2["./searched_obj"]
|
85
112
|
# dir_2["../dir_2/searched_obj"]
|
86
113
|
def [](path)
|
87
|
-
|
88
|
-
obj = case
|
114
|
+
first, *rest_path = path.split("/")
|
115
|
+
obj = case first
|
116
|
+
when nil
|
117
|
+
if path == "/"
|
118
|
+
root
|
119
|
+
elsif path == ""
|
120
|
+
self
|
121
|
+
end
|
89
122
|
when ""
|
90
|
-
|
123
|
+
root
|
91
124
|
when ".."
|
92
|
-
|
125
|
+
parent
|
93
126
|
when "."
|
94
127
|
self
|
95
128
|
else
|
96
|
-
|
129
|
+
children[first.to_sym]
|
97
130
|
end
|
98
131
|
|
99
|
-
if obj
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
132
|
+
return nil if obj.nil?
|
133
|
+
if rest_path.size > 0
|
134
|
+
obj[rest_path.join("/")]
|
135
|
+
else
|
136
|
+
obj
|
105
137
|
end
|
106
138
|
end
|
107
139
|
|
108
140
|
# Initial method for group description
|
109
141
|
#
|
110
142
|
# @example
|
111
|
-
# tree =
|
143
|
+
# tree = root :tree do
|
112
144
|
# with :param_1 => "some_param" do
|
113
145
|
# node :obj_1
|
114
146
|
# node :obj_2
|
@@ -128,7 +160,7 @@ module Lipa
|
|
128
160
|
# @param block of code
|
129
161
|
#
|
130
162
|
# @example
|
131
|
-
#
|
163
|
+
# root :tree do
|
132
164
|
# param_1 10
|
133
165
|
# param_2 run{ param_1 * 10 }
|
134
166
|
# end
|
@@ -159,7 +191,7 @@ module Lipa
|
|
159
191
|
# init_methods :folder
|
160
192
|
# end
|
161
193
|
#
|
162
|
-
# fls =
|
194
|
+
# fls = root :folders do
|
163
195
|
# folder :folder_1 do
|
164
196
|
# param_1 "some_param
|
165
197
|
# end
|
@@ -185,40 +217,39 @@ module Lipa
|
|
185
217
|
def self.add_node(name, parent, *args, &block)
|
186
218
|
# OPTIMIZE: This code looks bad
|
187
219
|
# Init from kind
|
188
|
-
attrs = {}
|
189
220
|
args[1] ||= {}
|
190
|
-
attrs
|
191
|
-
|
192
|
-
|
193
|
-
if
|
194
|
-
init_class = @@init_methods[
|
195
|
-
attrs[:kind] = kind.name
|
196
|
-
attrs.merge!(kind.attrs) do |key,v1,v2|
|
197
|
-
v1
|
198
|
-
end
|
221
|
+
attrs = {}
|
222
|
+
|
223
|
+
k = parent.root.kinds[name]
|
224
|
+
if k and k.for
|
225
|
+
init_class = @@init_methods[k.for]
|
199
226
|
else
|
200
227
|
#from init methods
|
201
228
|
init_class = @@init_methods[name]
|
202
229
|
end
|
203
230
|
|
204
231
|
if init_class
|
232
|
+
# Init general attributes
|
205
233
|
attrs[:parent] = parent
|
206
|
-
attrs[:
|
207
|
-
|
208
|
-
|
209
|
-
existen_child = parent.attrs[:children][child_name]
|
210
|
-
attrs = existen_child.attrs.merge(args[1]) if existen_child
|
211
|
-
|
212
|
-
args[1].merge!(attrs) do |key,v1,v2|
|
213
|
-
v1
|
214
|
-
end
|
234
|
+
attrs[:root] = parent.root
|
235
|
+
fn = parent.full_name == "/" ? "" : parent.full_name
|
236
|
+
attrs[:full_name] = fn + "/" + args[0].to_s
|
215
237
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
238
|
+
node_name = args[0].to_sym
|
239
|
+
children = parent.children
|
240
|
+
if k
|
241
|
+
attrs.merge! k.attrs
|
242
|
+
attrs[:kind] = k.name
|
243
|
+
#Node is descripted in kind
|
244
|
+
existen_child = parent.children[node_name]
|
245
|
+
attrs = existen_child.attrs.merge(attrs) if existen_child
|
246
|
+
#Init from kind
|
247
|
+
children[node_name] = init_class.send(:new, node_name, attrs, &k.block)
|
248
|
+
#Local modification
|
249
|
+
children[node_name].attrs.merge!(args[1])
|
250
|
+
children[node_name].instance_exec(&block) if block_given?
|
220
251
|
else
|
221
|
-
|
252
|
+
children[node_name] = init_class.send(:new, node_name, attrs.merge(args[1]), &block )
|
222
253
|
end
|
223
254
|
true
|
224
255
|
else
|
@@ -27,7 +27,7 @@ module Lipa
|
|
27
27
|
# Implementaion of root of description
|
28
28
|
# @example
|
29
29
|
#
|
30
|
-
# tree = Lipa::
|
30
|
+
# tree = Lipa::Root.new :tree do
|
31
31
|
# node :object do
|
32
32
|
# param_1 "some_param"
|
33
33
|
# param_2 run{param_1 + "!!!!"}
|
@@ -36,13 +36,19 @@ module Lipa
|
|
36
36
|
#
|
37
37
|
# tree.object.param_1 #=> "some_param"
|
38
38
|
# tree.object.param_2 #=> "some_param!!!!"
|
39
|
-
class
|
39
|
+
class Root < Node
|
40
40
|
attr_reader :kinds
|
41
41
|
@@trees = {}
|
42
|
-
def initialize(name,
|
42
|
+
def initialize(name, &block)
|
43
43
|
@kinds = {}
|
44
|
-
|
45
|
-
|
44
|
+
@root = self
|
45
|
+
@children = {}
|
46
|
+
@attrs = {}
|
47
|
+
@name = "/"
|
48
|
+
@full_name = "/"
|
49
|
+
|
50
|
+
instance_eval &block if block_given?
|
51
|
+
|
46
52
|
@@trees.merge! name.to_s => self
|
47
53
|
end
|
48
54
|
|
@@ -56,7 +62,6 @@ module Lipa
|
|
56
62
|
#
|
57
63
|
# some_kind :some_instance
|
58
64
|
def kind(name, attrs = {}, &block)
|
59
|
-
attrs = { :tree => self }
|
60
65
|
@kinds[name.to_sym] = Lipa::Kind.new(name, attrs, &block)
|
61
66
|
end
|
62
67
|
|
@@ -68,7 +73,7 @@ module Lipa
|
|
68
73
|
# @return [Node] node
|
69
74
|
#
|
70
75
|
# @example
|
71
|
-
# Lipa::
|
76
|
+
# Lipa::Root["some_tree://node_1/node_2"]
|
72
77
|
def self.[](uri)
|
73
78
|
tree, path = uri.split("://")
|
74
79
|
@@trees[tree][path] if @@trees[tree]
|
@@ -79,7 +84,7 @@ module Lipa
|
|
79
84
|
# @param path to file
|
80
85
|
#
|
81
86
|
# @example
|
82
|
-
#
|
87
|
+
# root "lipa" do
|
83
88
|
# load_from File.dirname(__FILE__) + "/data/part_of_tree.rb"
|
84
89
|
# end
|
85
90
|
def load_from(path)
|
data/lib/lipa/version.rb
CHANGED
data/spec/access_by_path_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'lipa'
|
|
2
2
|
|
3
3
|
describe "access to object by path in Unix style" do
|
4
4
|
before :all do
|
5
|
-
@tree =
|
5
|
+
@tree = root "lipa" do
|
6
6
|
node :obj_1 do
|
7
7
|
node :obj_2 do
|
8
8
|
node :obj_3 do
|
@@ -34,4 +34,12 @@ describe "access to object by path in Unix style" do
|
|
34
34
|
it 'should have access by absolute path' do
|
35
35
|
@node["/obj_1/obj_2/obj_3"].should eql(@tree.obj_1.obj_2.obj_3)
|
36
36
|
end
|
37
|
+
|
38
|
+
it 'should have access to self' do
|
39
|
+
@node[""].should eql(@node)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should have access to root' do
|
43
|
+
@node["/"].should eql(@tree)
|
44
|
+
end
|
37
45
|
end
|
data/spec/bunch_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'lipa'
|
|
2
2
|
|
3
3
|
describe Lipa::Bunch do
|
4
4
|
before :all do
|
5
|
-
@tree =
|
5
|
+
@tree = root "lipa" do
|
6
6
|
with :attr_1 => 100, :attr_2 => "attr_2" do
|
7
7
|
node :obj_4
|
8
8
|
node :obj_5
|
@@ -24,7 +24,7 @@ describe Lipa::Bunch do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should have "with" initial method' do
|
27
|
-
t =
|
27
|
+
t = root "t" do
|
28
28
|
with :attr_1 => 999 do
|
29
29
|
node :obj_1
|
30
30
|
end
|
@@ -33,7 +33,7 @@ describe Lipa::Bunch do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should work with kinds' do
|
36
|
-
t =
|
36
|
+
t = root "t" do
|
37
37
|
kind :some_kind, :for => :node
|
38
38
|
|
39
39
|
with :attr_1 => 999 do
|
data/spec/kind_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'lipa'
|
|
2
2
|
|
3
3
|
describe Lipa::Kind do
|
4
4
|
before :all do
|
5
|
-
@tree =
|
5
|
+
@tree = root :tree do
|
6
6
|
# Set #1
|
7
7
|
kind :object, :for => :node
|
8
8
|
kind :group, :for => :node do
|
@@ -54,4 +54,8 @@ describe Lipa::Kind do
|
|
54
54
|
@tree.folder_1.name.should eql("folder_1")
|
55
55
|
end
|
56
56
|
|
57
|
+
it 'should have attrs' do
|
58
|
+
@tree.folder_1.some_file.attrs.should eql({:ext => "txt", :size => 1024})
|
59
|
+
end
|
60
|
+
|
57
61
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'lipa'
|
2
2
|
|
3
3
|
describe Lipa::Node do
|
4
|
-
before :
|
5
|
-
@tree =
|
4
|
+
before :each do
|
5
|
+
@tree = root "lipa" do
|
6
6
|
node :group_1 do
|
7
7
|
any_attr "any attr"
|
8
8
|
|
@@ -16,7 +16,9 @@ describe Lipa::Node do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
node :other_object
|
19
|
+
node :other_object do
|
20
|
+
bool_attr false
|
21
|
+
end
|
20
22
|
|
21
23
|
kind :some_kind do
|
22
24
|
param_1 "something"
|
@@ -37,21 +39,6 @@ describe Lipa::Node do
|
|
37
39
|
@node = @tree["group_1/obj_1"]
|
38
40
|
end
|
39
41
|
|
40
|
-
it 'should have name' do
|
41
|
-
@node.name.should eql("obj_1")
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should have tree' do
|
45
|
-
@node.tree.should eql(@tree)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should kind' do
|
49
|
-
@tree["obj_x"].kind.should eql(:some_kind)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should have parent' do
|
53
|
-
@node.parent.should eql(@tree["group_1"])
|
54
|
-
end
|
55
42
|
|
56
43
|
it 'should have descripted attr_1 eql 5' do
|
57
44
|
@node.attr_1.should eql(5)
|
@@ -62,7 +49,6 @@ describe Lipa::Node do
|
|
62
49
|
end
|
63
50
|
|
64
51
|
it 'should have descripted attr_3 eql sum of attr_1 and attr_2' do
|
65
|
-
@node.attr_3.should eql(8)
|
66
52
|
@node.attr_2 = 10
|
67
53
|
@node.attr_3.should eql(15)
|
68
54
|
end
|
@@ -73,30 +59,31 @@ describe Lipa::Node do
|
|
73
59
|
end
|
74
60
|
|
75
61
|
it 'should have hash access for attrs' do
|
76
|
-
@node.attrs[:attr_1].should eql(
|
62
|
+
@node.attrs[:attr_1].should eql(5)
|
77
63
|
@node.attrs[:attr_1] = 9
|
78
64
|
@node.attrs[:attr_1].should eql(9)
|
79
65
|
end
|
80
66
|
|
81
|
-
it 'should have children' do
|
82
|
-
@node.children.values.should eql([@tree["group_1/obj_1/obj_2"], @tree["group_1/obj_1/obj_3"]])
|
83
|
-
end
|
84
|
-
|
85
67
|
it 'should have [] for access entry by path' do
|
86
68
|
@node["obj_3"].should eql(@tree["group_1/obj_1/obj_3"])
|
87
69
|
end
|
88
70
|
|
89
|
-
it 'should access for children by .' do
|
90
|
-
@node.obj_3.should eql(@tree["group_1/obj_1/obj_3"])
|
91
|
-
end
|
92
|
-
|
93
71
|
it 'should not have bug in tree of kind objects' do
|
94
|
-
@tree.obj_x.obj_y1.children.keys.should
|
95
|
-
@tree.obj_x.children.keys.should
|
96
|
-
@tree.obj_x.obj_y2.obj_z3.children.keys.should
|
72
|
+
@tree.obj_x.obj_y1.children.keys.should =~ [:obj_z1, :obj_z2]
|
73
|
+
@tree.obj_x.children.keys.should =~ [:obj_y1, :obj_y2]
|
74
|
+
@tree.obj_x.obj_y2.obj_z3.children.keys.should =~ []
|
97
75
|
end
|
98
76
|
|
99
77
|
it 'should have access other object by reference' do
|
100
78
|
@node.attr_4.should eql(@tree.other_object)
|
101
79
|
end
|
80
|
+
|
81
|
+
it 'should have attrs with false ' do
|
82
|
+
@tree['other_object'].bool_attr.should be_false
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should have eval attrs read only' do
|
86
|
+
@node.eval_attrs.should eql({:attr_1 => 5, :attr_2 => 3, :attr_3 => 8, :attr_4 => @node["/other_object"]})
|
87
|
+
end
|
88
|
+
|
102
89
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'lipa'
|
2
|
+
|
3
|
+
describe Lipa::Node do
|
4
|
+
before :all do
|
5
|
+
@tree = root "lipa" do
|
6
|
+
node :group_1 do
|
7
|
+
node :obj_1, :attr_1 => 5 do
|
8
|
+
|
9
|
+
node :obj_2
|
10
|
+
node :obj_3
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
kind :some_kind do
|
15
|
+
param_1 "something"
|
16
|
+
end
|
17
|
+
|
18
|
+
some_kind :obj_x
|
19
|
+
end
|
20
|
+
@node = @tree["group_1/obj_1"]
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should have name' do
|
24
|
+
@node.name.should eql("obj_1")
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should have full_name' do
|
28
|
+
@node.full_name.should eql("/group_1/obj_1")
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should have root' do
|
32
|
+
@node.root.should eql(@tree)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should kind' do
|
36
|
+
@tree["obj_x"].kind.should eql(:some_kind)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should have parent' do
|
40
|
+
@node.parent.should eql(@tree["group_1"])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should have children' do
|
44
|
+
@node.children.values.should =~ [@tree["group_1/obj_1/obj_2"], @tree["group_1/obj_1/obj_3"]]
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should access for children by .' do
|
48
|
+
@node.obj_3.should eql(@tree["group_1/obj_1/obj_3"])
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should not have attrs indentical withi instance varianles' do
|
52
|
+
[:attrs, :name, :children, :root, :parent, :full_name, :kind].each do |n|
|
53
|
+
@node.attrs.include?(n).should be_false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'lipa'
|
2
2
|
|
3
|
-
describe Lipa::
|
3
|
+
describe Lipa::Root do
|
4
4
|
before :all do
|
5
|
-
@tree =
|
5
|
+
@tree = root "lipa" do
|
6
6
|
node :group_1 do
|
7
7
|
any_attr "any attr"
|
8
8
|
|
@@ -19,12 +19,29 @@ describe Lipa::Tree do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
it 'should have name "/"' do
|
23
|
+
@tree.name.should eql("/")
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should have full_name "/"' do
|
27
|
+
@tree.full_name.should eql("/")
|
28
|
+
end
|
29
|
+
|
22
30
|
it "should have access any object in trees" do
|
23
|
-
Lipa::
|
31
|
+
Lipa::Root["lipa://group_1/obj_1"].should eql(@tree["group_1/obj_1"])
|
24
32
|
end
|
25
33
|
|
26
34
|
it 'should load description from files' do
|
27
35
|
@tree.external_node.msg.should eql("Hello!")
|
28
36
|
end
|
37
|
+
|
38
|
+
it 'should support absolute path for access to object' do
|
39
|
+
@tree["/group_1/obj_1"].should eql(@tree["group_1/obj_1"])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should support root access' do
|
43
|
+
@tree[""].should eql(@tree)
|
44
|
+
end
|
45
|
+
|
29
46
|
end
|
30
47
|
|
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.
|
4
|
+
version: 1.0.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-
|
12
|
+
date: 2011-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70409320 !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: *
|
24
|
+
version_requirements: *70409320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70409020 !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: *
|
35
|
+
version_requirements: *70409020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70408690 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70408690
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yard
|
49
|
-
requirement: &
|
49
|
+
requirement: &70408390 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70408390
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rdiscount
|
60
|
-
requirement: &
|
60
|
+
requirement: &70408090 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70408090
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
|
-
requirement: &
|
71
|
+
requirement: &70407720 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70407720
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: notes
|
82
|
-
requirement: &
|
82
|
+
requirement: &70407480 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,18 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70407480
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: guard-rspec
|
93
|
+
requirement: &70407220 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70407220
|
91
102
|
description:
|
92
103
|
email: atimin@gmail.com
|
93
104
|
executables: []
|
@@ -96,17 +107,18 @@ extra_rdoc_files:
|
|
96
107
|
- README.md
|
97
108
|
- NEWS.md
|
98
109
|
files:
|
99
|
-
- lib/lipa.rb
|
100
|
-
- lib/lipa/version.rb
|
101
110
|
- lib/lipa/kind.rb
|
111
|
+
- lib/lipa/version.rb
|
102
112
|
- lib/lipa/node.rb
|
113
|
+
- lib/lipa/root.rb
|
103
114
|
- lib/lipa/bunch.rb
|
104
|
-
- lib/lipa
|
105
|
-
- spec/
|
106
|
-
- spec/
|
107
|
-
- spec/kind_spec.rb
|
108
|
-
- spec/bunch_spec.rb
|
115
|
+
- lib/lipa.rb
|
116
|
+
- spec/node_attrs_spec.rb
|
117
|
+
- spec/root_spec.rb
|
109
118
|
- spec/access_by_path_spec.rb
|
119
|
+
- spec/node_vars_spec.rb
|
120
|
+
- spec/bunch_spec.rb
|
121
|
+
- spec/kind_spec.rb
|
110
122
|
- examples/simple_tree.rb
|
111
123
|
- examples/universe.rb
|
112
124
|
- examples/store.rb
|
@@ -138,8 +150,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
150
|
version: '0'
|
139
151
|
requirements: []
|
140
152
|
rubyforge_project:
|
141
|
-
rubygems_version: 1.8.
|
153
|
+
rubygems_version: 1.8.10
|
142
154
|
signing_key:
|
143
155
|
specification_version: 3
|
144
156
|
summary: Lipa - DSL for description treelike structures in Ruby
|
145
157
|
test_files: []
|
158
|
+
has_rdoc:
|