yagni 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rvmrc +55 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +32 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +59 -0
- data/lib/yell/hash.rb +122 -0
- data/lib/yell/version.rb +5 -0
- data/lib/yell.rb +6 -0
- data/rdoc/README_rdoc.html +132 -0
- data/rdoc/Yell/Hash.html +554 -0
- data/rdoc/Yell.html +158 -0
- data/rdoc/created.rid +5 -0
- data/rdoc/index.html +72 -0
- data/rdoc/lib/yell/hash_rb.html +55 -0
- data/rdoc/lib/yell/version_rb.html +55 -0
- data/rdoc/lib/yell_rb.html +52 -0
- data/rdoc/rdoc.css +706 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/yell/hash_spec.rb +83 -0
- metadata +122 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe Yell::Hash do
|
4
|
+
|
5
|
+
TEST_PREFIX = 'yell_unit_test'
|
6
|
+
|
7
|
+
def self.test_cases(options={})
|
8
|
+
it 'should raise NoMethodError on non-existent key' do
|
9
|
+
expect { subject.fake_key }.to raise_exception NoMethodError
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should respond to key names' do
|
13
|
+
subject.load_data if options[:block]
|
14
|
+
subject.respond_to?(:simple).should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return value on simple key' do
|
18
|
+
subject.simple.should == 'not nested'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should return correct value on single nested key' do
|
22
|
+
subject.nested.simple.should == 'value'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return correct value on double nested key' do
|
26
|
+
subject.nested_twice.first.key.foo.should == 'nested'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should reload the object' do
|
30
|
+
subject.simple.should == 'not nested'
|
31
|
+
subject.reload
|
32
|
+
subject.nested.simple.should == 'value'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
context 'when it is given a hash' do
|
38
|
+
|
39
|
+
subject { Yell::Hash.new(build_hash) }
|
40
|
+
|
41
|
+
def build_hash
|
42
|
+
{
|
43
|
+
'simple' => 'not nested',
|
44
|
+
:nested => { :simple => 'value' },
|
45
|
+
:nested_twice => { :first => { :key => { :foo => 'nested' } } }
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
test_cases
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
# here we test the functionality for JSON as an example for the block usage.
|
54
|
+
# Any format is supported as long as there is a form to extract the
|
55
|
+
# corresponding hash and pass it in a block.
|
56
|
+
|
57
|
+
context 'when it is given a block' do
|
58
|
+
require 'json'
|
59
|
+
|
60
|
+
def json
|
61
|
+
<<-END
|
62
|
+
{
|
63
|
+
"simple": "not nested",
|
64
|
+
"nested": {
|
65
|
+
"simple": "value"
|
66
|
+
},
|
67
|
+
"nested_twice": {
|
68
|
+
"first": {
|
69
|
+
"key": {
|
70
|
+
"foo": "nested"
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
END
|
76
|
+
end
|
77
|
+
|
78
|
+
subject { Yell::Hash.new { JSON.parse json } }
|
79
|
+
|
80
|
+
test_cases(:block => true)
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yagni
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.2'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Fabio de Lima Pereira
|
9
|
+
- Rafael Regis do Prado
|
10
|
+
- Renato Mascarenhas
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2011-11-10 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
requirement: &3181180 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *3181180
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: guard-rspec
|
29
|
+
requirement: &3194000 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *3194000
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bundler
|
40
|
+
requirement: &3191720 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *3191720
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: jeweler
|
51
|
+
requirement: &3190020 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *3190020
|
60
|
+
description: ! " yell provides an easy way to access your hash values using its\n
|
61
|
+
\ simple, method-like notation. Useful when parsing complex hashes,\n or loading
|
62
|
+
YAML or JSON files (but not limited to that!) and being\n able to access your
|
63
|
+
data in an elegant manner \n"
|
64
|
+
email: renato.mascosta@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files:
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.rdoc
|
70
|
+
files:
|
71
|
+
- .document
|
72
|
+
- .rspec
|
73
|
+
- .rvmrc
|
74
|
+
- Gemfile
|
75
|
+
- Gemfile.lock
|
76
|
+
- Guardfile
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.rdoc
|
79
|
+
- Rakefile
|
80
|
+
- lib/yell.rb
|
81
|
+
- lib/yell/hash.rb
|
82
|
+
- lib/yell/version.rb
|
83
|
+
- rdoc/README_rdoc.html
|
84
|
+
- rdoc/Yell.html
|
85
|
+
- rdoc/Yell/Hash.html
|
86
|
+
- rdoc/created.rid
|
87
|
+
- rdoc/index.html
|
88
|
+
- rdoc/lib/yell/hash_rb.html
|
89
|
+
- rdoc/lib/yell/version_rb.html
|
90
|
+
- rdoc/lib/yell_rb.html
|
91
|
+
- rdoc/rdoc.css
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/yell/hash_spec.rb
|
94
|
+
homepage: http://github.com/rmascarenhas/yell
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: 3891352656799281921
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.10
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: yell is a simple hash library which aims to provide a method-like access
|
122
|
+
test_files: []
|