ytools 0.1.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/Rakefile +52 -0
- data/bin/ypath +5 -0
- data/bin/ytemplates +5 -0
- data/lib/VERSION +1 -0
- data/lib/ytools/basecli.rb +67 -0
- data/lib/ytools/errors.rb +7 -0
- data/lib/ytools/path/cli.rb +103 -0
- data/lib/ytools/path/examples.txt +64 -0
- data/lib/ytools/path/executor.rb +58 -0
- data/lib/ytools/path/lexer.rb +166 -0
- data/lib/ytools/path/parser.rb +135 -0
- data/lib/ytools/path/selectors.rb +132 -0
- data/lib/ytools/templates/cli.rb +108 -0
- data/lib/ytools/templates/examples.txt +52 -0
- data/lib/ytools/templates/executor.rb +28 -0
- data/lib/ytools/templates/yaml_object.rb +11 -0
- data/lib/ytools/version.rb +12 -0
- data/lib/ytools/yaml_object.rb +112 -0
- data/lib/ytools/yreader.rb +21 -0
- data/spec/helpers.rb +15 -0
- data/spec/path/executor_spec.rb +45 -0
- data/spec/path/lexer_spec.rb +127 -0
- data/spec/path/parser_spec.rb +104 -0
- data/spec/path/selectors_spec.rb +123 -0
- data/spec/path/yamls/1.yml +2 -0
- data/spec/path/yamls/2.yml +2 -0
- data/spec/path/yamls/3.yml +6 -0
- data/spec/path/yamls/4.yml +12 -0
- data/spec/path/yamls/5.yml +4 -0
- data/spec/yaml_object_spec.rb +61 -0
- metadata +118 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'ytools/errors'
|
2
|
+
require 'ytools/yaml_object'
|
3
|
+
require 'ytools/path/selectors'
|
4
|
+
|
5
|
+
require 'helpers'
|
6
|
+
|
7
|
+
module YTools::Path
|
8
|
+
|
9
|
+
describe "ChildSelector" do
|
10
|
+
include YamlObjectHelper
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
@obj = yo({'a' => {'b' => 'c', 'd' => 'e'}})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to get the child node name" do
|
17
|
+
cs = ChildSelector.new('a')
|
18
|
+
cs.child.should eql('a')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to select a single child element" do
|
22
|
+
cs = ChildSelector.new('a')
|
23
|
+
cs.select(@obj).b.should eql('c')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can chain child selectors together" do
|
27
|
+
ca = ChildSelector.new('a')
|
28
|
+
cb = ChildSelector.new('b')
|
29
|
+
cc = ChildSelector.new('c')
|
30
|
+
|
31
|
+
ca.chain(cb)
|
32
|
+
ca.chain(cc)
|
33
|
+
|
34
|
+
ca.subselector.should be(cb)
|
35
|
+
cb.subselector.should be(cc)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be able to chain selectors to find children" do
|
39
|
+
ca = ChildSelector.new('a')
|
40
|
+
cb = ChildSelector.new('b')
|
41
|
+
ca.chain(cb)
|
42
|
+
|
43
|
+
ca.select(@obj).should eql('c')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "IndexSelector" do
|
48
|
+
include YamlObjectHelper
|
49
|
+
|
50
|
+
before :each do
|
51
|
+
@obj = yo({'a' => {'b' => [1,2,3,4,5], 'c' => ['x', ['y', 'z']]}})
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should be retrieve the index" do
|
55
|
+
is = IndexSelector.new(2)
|
56
|
+
is.index.should eql(2)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should retrieve a simple index" do
|
60
|
+
is = IndexSelector.new(2)
|
61
|
+
is.select(@obj.a.b).should eql(3)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should retrieve be able to chain to subselectors" do
|
65
|
+
i1 = IndexSelector.new(1)
|
66
|
+
i2 = IndexSelector.new(0)
|
67
|
+
|
68
|
+
i1.chain(i2)
|
69
|
+
i1.select(@obj.a.c).should eql('y')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "RootSelector" do
|
74
|
+
include YamlObjectHelper
|
75
|
+
|
76
|
+
before :each do
|
77
|
+
@obj = yo({'a' => {'b' => [1,2,3,4,5], 'c' => ['x', ['y', 'z']]}})
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should retrieve the root path from any child" do
|
81
|
+
rs = RootSelector.new
|
82
|
+
rs.select(@obj.a).should be(@obj)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "DescendantSelector" do
|
87
|
+
include YamlObjectHelper
|
88
|
+
|
89
|
+
it "should set the match property correctly" do
|
90
|
+
DescendantSelector.new('b').match.should eql('b')
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should pull out a single set of objects" do
|
94
|
+
ms = DescendantSelector.new('b')
|
95
|
+
o = yo({'a' => {'b' => {'b' => 'c'}}, 'b' => 'd'})
|
96
|
+
|
97
|
+
ms.select(o).length.should eql(3)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should pull nodes from arrays as well" do
|
101
|
+
ms = DescendantSelector.new('b')
|
102
|
+
o = yo({'a' => {'b' => 'c'}, 'b' => [{'x' => 'y', 'b' => 'd'}, {'b' => 'q'}]})
|
103
|
+
|
104
|
+
found = ms.select(o)
|
105
|
+
found.length.should eql(4)
|
106
|
+
found[0].should eql('c')
|
107
|
+
found[1].should be_a(Array)
|
108
|
+
found[2].should eql('d')
|
109
|
+
found[3].should eql('q')
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should be able to cull specific subselectors" do
|
113
|
+
ms = DescendantSelector.new('c')
|
114
|
+
ms.chain(IndexSelector.new(1))
|
115
|
+
o = yo({'a' => {'b' => {'c' => [1, 2, 3]}}, 'c' => ['a', 'b', 'c']})
|
116
|
+
|
117
|
+
found = ms.select(o)
|
118
|
+
found.length.should eql(2)
|
119
|
+
found[0].should eql(2)
|
120
|
+
found[1].should eql('b')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'ytools/errors'
|
2
|
+
require 'ytools/yaml_object'
|
3
|
+
require 'helpers'
|
4
|
+
|
5
|
+
module YTools
|
6
|
+
describe "Yaml Object" do
|
7
|
+
include YamlObjectHelper
|
8
|
+
|
9
|
+
it "should retrieve keys that exist." do
|
10
|
+
h = yo({'a' => 'b'})
|
11
|
+
h['a'].should eql('b')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should create method definitions yor keys" do
|
15
|
+
h = yo({'a' => 'b'})
|
16
|
+
h.a.should eql('b')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not spread the logic yor accessors across entire classes" do
|
20
|
+
a = yo({'a' => 'b'})
|
21
|
+
b = yo({'b' => 'c'})
|
22
|
+
|
23
|
+
a.a.should eql('b')
|
24
|
+
b.b.should eql('c')
|
25
|
+
attempting { b.a }.should raise_error(YTools::PathError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be able to retrieve the its ypath." do
|
29
|
+
h = yo({'a' => {'b' => 'c'}})
|
30
|
+
h.ypath.should eql('/')
|
31
|
+
h.a.ypath.should eql('/a')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should format the path of array children correctly." do
|
35
|
+
h = yo({'a' => [{'b' => 'c'}, {'d' => {'e' => 'f'}}]})
|
36
|
+
h.a[0].ypath.should eql('/a[0]')
|
37
|
+
h.a[1].d.ypath.should eql('/a[1]/d')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should format funky child path names correctly in paths." do
|
41
|
+
h = yo({'a' => {'b/c' => {'d' => 'e'}}})
|
42
|
+
h.a['b/c'].ypath.should eql("/a/|b/c|")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should format child paths with dots correctly." do
|
46
|
+
h = yo({'a' => {'b.c' => {'d' => 'e'}}})
|
47
|
+
h.a.b_c.ypath.should eql('/a/b.c')
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should allow funky characters in paths but not method names" do
|
51
|
+
h = yo({'a' => {'@b' => {'c' => 'd'}}})
|
52
|
+
attempting { h.a.b }.should raise_error(YTools::PathError)
|
53
|
+
h.a['@b'].ypath.should eql('/a/|@b|')
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should fail when a key is not present." do
|
57
|
+
h = yo({'a' => 'b'})
|
58
|
+
attempting { h['c'] }.should raise_error(YTools::PathError)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ytools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Gabe McArthur
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-14 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
version: 1.3.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Installs the ypath tool for reading YAML files using an XPath-like syntax. Installs the ytemplates tool for writing ERB templates using YAML files as the template binding object.
|
38
|
+
email:
|
39
|
+
- madeonamac@gmail.com
|
40
|
+
executables:
|
41
|
+
- ypath
|
42
|
+
- ytemplates
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- Rakefile
|
49
|
+
- bin/ypath
|
50
|
+
- bin/ytemplates
|
51
|
+
- lib/VERSION
|
52
|
+
- lib/ytools/basecli.rb
|
53
|
+
- lib/ytools/errors.rb
|
54
|
+
- lib/ytools/path/cli.rb
|
55
|
+
- lib/ytools/path/examples.txt
|
56
|
+
- lib/ytools/path/executor.rb
|
57
|
+
- lib/ytools/path/lexer.rb
|
58
|
+
- lib/ytools/path/parser.rb
|
59
|
+
- lib/ytools/path/selectors.rb
|
60
|
+
- lib/ytools/templates/cli.rb
|
61
|
+
- lib/ytools/templates/examples.txt
|
62
|
+
- lib/ytools/templates/executor.rb
|
63
|
+
- lib/ytools/templates/yaml_object.rb
|
64
|
+
- lib/ytools/version.rb
|
65
|
+
- lib/ytools/yaml_object.rb
|
66
|
+
- lib/ytools/yreader.rb
|
67
|
+
- spec/helpers.rb
|
68
|
+
- spec/path/executor_spec.rb
|
69
|
+
- spec/path/lexer_spec.rb
|
70
|
+
- spec/path/parser_spec.rb
|
71
|
+
- spec/path/selectors_spec.rb
|
72
|
+
- spec/path/yamls/1.yml
|
73
|
+
- spec/path/yamls/2.yml
|
74
|
+
- spec/path/yamls/3.yml
|
75
|
+
- spec/path/yamls/4.yml
|
76
|
+
- spec/path/yamls/5.yml
|
77
|
+
- spec/yaml_object_spec.rb
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: http://github.com/gabemc/ytools
|
80
|
+
licenses: []
|
81
|
+
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options:
|
84
|
+
- --charset=UTF-8
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.3.7
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: For reading or writing configuration files using YAML.
|
112
|
+
test_files:
|
113
|
+
- spec/helpers.rb
|
114
|
+
- spec/yaml_object_spec.rb
|
115
|
+
- spec/path/lexer_spec.rb
|
116
|
+
- spec/path/executor_spec.rb
|
117
|
+
- spec/path/selectors_spec.rb
|
118
|
+
- spec/path/parser_spec.rb
|