hashie 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +16 -0
- data/CONTRIBUTING.md +27 -0
- data/Guardfile +1 -1
- data/README.markdown +240 -0
- data/VERSION +1 -0
- data/hashie.gemspec +4 -2
- data/lib/hashie.rb +20 -6
- data/lib/hashie/dash.rb +21 -8
- data/lib/hashie/extensions/coercion.rb +105 -0
- data/lib/hashie/extensions/deep_merge.rb +21 -0
- data/lib/hashie/extensions/indifferent_access.rb +114 -0
- data/lib/hashie/extensions/key_conversion.rb +92 -0
- data/lib/hashie/extensions/merge_initializer.rb +26 -0
- data/lib/hashie/extensions/method_access.rb +124 -0
- data/lib/hashie/extensions/structure.rb +47 -0
- data/lib/hashie/hash.rb +12 -6
- data/lib/hashie/mash.rb +48 -17
- data/lib/hashie/trash.rb +41 -5
- data/lib/hashie/version.rb +1 -1
- data/spec/hashie/dash_spec.rb +25 -0
- data/spec/hashie/extensions/coercion_spec.rb +89 -0
- data/spec/hashie/extensions/deep_merge_spec.rb +20 -0
- data/spec/hashie/extensions/indifferent_access_spec.rb +74 -0
- data/spec/hashie/extensions/key_conversion_spec.rb +102 -0
- data/spec/hashie/extensions/merge_initializer_spec.rb +20 -0
- data/spec/hashie/extensions/method_access_spec.rb +112 -0
- data/spec/hashie/hash_spec.rb +2 -12
- data/spec/hashie/mash_spec.rb +105 -17
- data/spec/hashie/trash_spec.rb +75 -0
- metadata +72 -24
- data/Gemfile.lock +0 -34
- data/README.rdoc +0 -120
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michael Bleigh
|
9
|
+
- Jerry Cheung
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2013-02-16 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rake
|
16
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ~>
|
@@ -21,10 +22,15 @@ dependencies:
|
|
21
22
|
version: 0.9.2
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 0.9.2
|
25
31
|
- !ruby/object:Gem::Dependency
|
26
32
|
name: rspec
|
27
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
28
34
|
none: false
|
29
35
|
requirements:
|
30
36
|
- - ~>
|
@@ -32,10 +38,15 @@ dependencies:
|
|
32
38
|
version: '2.5'
|
33
39
|
type: :development
|
34
40
|
prerelease: false
|
35
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.5'
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: guard
|
38
|
-
requirement:
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,31 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
47
63
|
- !ruby/object:Gem::Dependency
|
48
64
|
name: guard-rspec
|
49
|
-
requirement:
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: growl
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
50
82
|
none: false
|
51
83
|
requirements:
|
52
84
|
- - ! '>='
|
@@ -54,11 +86,17 @@ dependencies:
|
|
54
86
|
version: '0'
|
55
87
|
type: :development
|
56
88
|
prerelease: false
|
57
|
-
version_requirements:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
58
95
|
description: Hashie is a small collection of tools that make hashes more powerful.
|
59
96
|
Currently includes Mash (Mocking Hash) and Dash (Discrete Hash).
|
60
97
|
email:
|
61
98
|
- michael@intridea.com
|
99
|
+
- jollyjerry@gmail.com
|
62
100
|
executables: []
|
63
101
|
extensions: []
|
64
102
|
extra_rdoc_files: []
|
@@ -67,16 +105,26 @@ files:
|
|
67
105
|
- .gitignore
|
68
106
|
- .rspec
|
69
107
|
- .travis.yml
|
108
|
+
- .yardopts
|
109
|
+
- CHANGELOG.md
|
110
|
+
- CONTRIBUTING.md
|
70
111
|
- Gemfile
|
71
|
-
- Gemfile.lock
|
72
112
|
- Guardfile
|
73
113
|
- LICENSE
|
74
|
-
- README.
|
114
|
+
- README.markdown
|
75
115
|
- Rakefile
|
116
|
+
- VERSION
|
76
117
|
- hashie.gemspec
|
77
118
|
- lib/hashie.rb
|
78
119
|
- lib/hashie/clash.rb
|
79
120
|
- lib/hashie/dash.rb
|
121
|
+
- lib/hashie/extensions/coercion.rb
|
122
|
+
- lib/hashie/extensions/deep_merge.rb
|
123
|
+
- lib/hashie/extensions/indifferent_access.rb
|
124
|
+
- lib/hashie/extensions/key_conversion.rb
|
125
|
+
- lib/hashie/extensions/merge_initializer.rb
|
126
|
+
- lib/hashie/extensions/method_access.rb
|
127
|
+
- lib/hashie/extensions/structure.rb
|
80
128
|
- lib/hashie/hash.rb
|
81
129
|
- lib/hashie/hash_extensions.rb
|
82
130
|
- lib/hashie/mash.rb
|
@@ -84,13 +132,20 @@ files:
|
|
84
132
|
- lib/hashie/version.rb
|
85
133
|
- spec/hashie/clash_spec.rb
|
86
134
|
- spec/hashie/dash_spec.rb
|
135
|
+
- spec/hashie/extensions/coercion_spec.rb
|
136
|
+
- spec/hashie/extensions/deep_merge_spec.rb
|
137
|
+
- spec/hashie/extensions/indifferent_access_spec.rb
|
138
|
+
- spec/hashie/extensions/key_conversion_spec.rb
|
139
|
+
- spec/hashie/extensions/merge_initializer_spec.rb
|
140
|
+
- spec/hashie/extensions/method_access_spec.rb
|
87
141
|
- spec/hashie/hash_spec.rb
|
88
142
|
- spec/hashie/mash_spec.rb
|
89
143
|
- spec/hashie/trash_spec.rb
|
90
144
|
- spec/spec.opts
|
91
145
|
- spec/spec_helper.rb
|
92
146
|
homepage: https://github.com/intridea/hashie
|
93
|
-
licenses:
|
147
|
+
licenses:
|
148
|
+
- MIT
|
94
149
|
post_install_message:
|
95
150
|
rdoc_options: []
|
96
151
|
require_paths:
|
@@ -103,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
158
|
version: '0'
|
104
159
|
segments:
|
105
160
|
- 0
|
106
|
-
hash:
|
161
|
+
hash: 3365405731084107333
|
107
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
163
|
none: false
|
109
164
|
requirements:
|
@@ -112,18 +167,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
167
|
version: '0'
|
113
168
|
segments:
|
114
169
|
- 0
|
115
|
-
hash:
|
170
|
+
hash: 3365405731084107333
|
116
171
|
requirements: []
|
117
172
|
rubyforge_project:
|
118
|
-
rubygems_version: 1.8.
|
173
|
+
rubygems_version: 1.8.23
|
119
174
|
signing_key:
|
120
175
|
specification_version: 3
|
121
176
|
summary: Your friendly neighborhood hash toolkit.
|
122
|
-
test_files:
|
123
|
-
- spec/hashie/clash_spec.rb
|
124
|
-
- spec/hashie/dash_spec.rb
|
125
|
-
- spec/hashie/hash_spec.rb
|
126
|
-
- spec/hashie/mash_spec.rb
|
127
|
-
- spec/hashie/trash_spec.rb
|
128
|
-
- spec/spec.opts
|
129
|
-
- spec/spec_helper.rb
|
177
|
+
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
hashie (1.2.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.1.2)
|
10
|
-
guard (0.5.1)
|
11
|
-
thor (~> 0.14.6)
|
12
|
-
guard-rspec (0.4.0)
|
13
|
-
guard (>= 0.4.0)
|
14
|
-
rake (0.9.2)
|
15
|
-
rspec (2.6.0)
|
16
|
-
rspec-core (~> 2.6.0)
|
17
|
-
rspec-expectations (~> 2.6.0)
|
18
|
-
rspec-mocks (~> 2.6.0)
|
19
|
-
rspec-core (2.6.4)
|
20
|
-
rspec-expectations (2.6.0)
|
21
|
-
diff-lcs (~> 1.1.2)
|
22
|
-
rspec-mocks (2.6.0)
|
23
|
-
thor (0.14.6)
|
24
|
-
|
25
|
-
PLATFORMS
|
26
|
-
java
|
27
|
-
ruby
|
28
|
-
|
29
|
-
DEPENDENCIES
|
30
|
-
guard
|
31
|
-
guard-rspec
|
32
|
-
hashie!
|
33
|
-
rake (~> 0.9.2)
|
34
|
-
rspec (~> 2.5)
|
data/README.rdoc
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
= Hashie
|
2
|
-
|
3
|
-
Hashie is a growing collection of tools that extend Hashes and make
|
4
|
-
them more useful.
|
5
|
-
|
6
|
-
== Installation
|
7
|
-
|
8
|
-
Hashie is available as a RubyGem:
|
9
|
-
|
10
|
-
gem install hashie
|
11
|
-
|
12
|
-
== Mash
|
13
|
-
|
14
|
-
Mash is an extended Hash that gives simple pseudo-object functionality
|
15
|
-
that can be built from hashes and easily extended. It is designed to
|
16
|
-
be used in RESTful API libraries to provide easy object-like access
|
17
|
-
to JSON and XML parsed hashes.
|
18
|
-
|
19
|
-
=== Example:
|
20
|
-
|
21
|
-
mash = Hashie::Mash.new
|
22
|
-
mash.name? # => false
|
23
|
-
mash.name # => nil
|
24
|
-
mash.name = "My Mash"
|
25
|
-
mash.name # => "My Mash"
|
26
|
-
mash.name? # => true
|
27
|
-
mash.inspect # => <Hashie::Mash name="My Mash">
|
28
|
-
|
29
|
-
mash = Mash.new
|
30
|
-
# use bang methods for multi-level assignment
|
31
|
-
mash.author!.name = "Michael Bleigh"
|
32
|
-
mash.author # => <Hashie::Mash name="Michael Bleigh">
|
33
|
-
|
34
|
-
<b>Note:</b> The <tt>?</tt> method will return false if a key has been set
|
35
|
-
to false or nil. In order to check if a key has been set at all, use the
|
36
|
-
<tt>mash.key?('some_key')</tt> method instead.
|
37
|
-
|
38
|
-
== Dash
|
39
|
-
|
40
|
-
Dash is an extended Hash that has a discrete set of defined properties
|
41
|
-
and only those properties may be set on the hash. Additionally, you
|
42
|
-
can set defaults for each property. You can also flag a property as
|
43
|
-
required. Required properties will raise an execption if unset.
|
44
|
-
|
45
|
-
=== Example:
|
46
|
-
|
47
|
-
class Person < Hashie::Dash
|
48
|
-
property :name, :required => true
|
49
|
-
property :email
|
50
|
-
property :occupation, :default => 'Rubyist'
|
51
|
-
end
|
52
|
-
|
53
|
-
p = Person.new # => ArgumentError: The property 'name' is required for this Dash.
|
54
|
-
|
55
|
-
p = Person.new(:name => "Bob")
|
56
|
-
p.name # => 'Bob'
|
57
|
-
p.name = nil # => ArgumentError: The property 'name' is required for this Dash.
|
58
|
-
p.email = 'abc@def.com'
|
59
|
-
p.occupation # => 'Rubyist'
|
60
|
-
p.email # => 'abc@def.com'
|
61
|
-
p[:awesome] # => NoMethodError
|
62
|
-
p[:occupation] # => 'Rubyist'
|
63
|
-
|
64
|
-
== Trash
|
65
|
-
|
66
|
-
A Trash is a Dash that allows you to translate keys on initialization.
|
67
|
-
It is used like so:
|
68
|
-
|
69
|
-
class Person < Hashie::Trash
|
70
|
-
property :first_name, :from => :firstName
|
71
|
-
end
|
72
|
-
|
73
|
-
This will automatically translate the <tt>firstName</tt> key to <tt>first_name</tt>
|
74
|
-
when it is initialized using a hash such as through:
|
75
|
-
|
76
|
-
Person.new(:firstName => 'Bob')
|
77
|
-
|
78
|
-
== Clash
|
79
|
-
|
80
|
-
Clash is a Chainable Lazy Hash that allows you to easily construct
|
81
|
-
complex hashes using method notation chaining. This will allow you
|
82
|
-
to use a more action-oriented approach to building options hashes.
|
83
|
-
|
84
|
-
Essentially, a Clash is a generalized way to provide much of the same
|
85
|
-
kind of "chainability" that libraries like Arel or Rails 2.x's named_scopes
|
86
|
-
provide.
|
87
|
-
|
88
|
-
=== Example
|
89
|
-
|
90
|
-
c = Hashie::Clash.new
|
91
|
-
c.where(:abc => 'def').order(:created_at)
|
92
|
-
c # => {:where => {:abc => 'def}, :order => :created_at}
|
93
|
-
|
94
|
-
# You can also use bang notation to chain into sub-hashes,
|
95
|
-
# jumping back up the chain with _end!
|
96
|
-
c = Hashie::Clash.new
|
97
|
-
c.where!.abc('def').ghi(123)._end!.order(:created_at)
|
98
|
-
c # => {:where => {:abc => 'def', :ghi => 123}, :order => :created_at}
|
99
|
-
|
100
|
-
# Multiple hashes are merged automatically
|
101
|
-
c = Hashie::Clash.new
|
102
|
-
c.where(:abc => 'def').where(:hgi => 123)
|
103
|
-
c # => {:where => {:abc => 'def', :hgi => 123}}
|
104
|
-
|
105
|
-
|
106
|
-
== Note on Patches/Pull Requests
|
107
|
-
|
108
|
-
* Fork the project.
|
109
|
-
* Make your feature addition or bug fix.
|
110
|
-
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
111
|
-
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
112
|
-
* Send me a pull request. Bonus points for topic branches.
|
113
|
-
|
114
|
-
== Authors
|
115
|
-
|
116
|
-
* Michael Bleigh
|
117
|
-
|
118
|
-
== Copyright
|
119
|
-
|
120
|
-
Copyright (c) 2009 Intridea, Inc (http://intridea.com/). See LICENSE for details.
|