restify 0.3.0.1.b48 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MGRjNjQzM2ExOGRiNjQ4Y2I0MDAzZWVlODRkMTc3YWYyZDhmMGY2Mg==
5
- data.tar.gz: !binary |-
6
- MjFlODU2YTYyMjczYTg5OTc3ZDc4N2IzM2EzYzFjMDlhZDAyYjA0YQ==
2
+ SHA1:
3
+ metadata.gz: 3dc2e74127b0f74bb9ca00c33f428a5990219ba4
4
+ data.tar.gz: 76641ed9d9a00ec935d1797609ef03a68b0ad2cc
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NGRhOTI1YWY4ZmI1MmY3ZjRjNDdkZGIzMmI3YmQ0Y2VkODI4ZDFiOWI0ZjRj
10
- MDk2Yzk2NmNmYjUxNzE5YWM1ZDNkYmQ0MjEzMTY1NDVmMWIzMTMxYjhjYTU0
11
- OTU4ODI2NmViMmQyZDZiZTkyYjE1ZjRiZjA2YTc0NGY2MTUyODg=
12
- data.tar.gz: !binary |-
13
- ODJjNjkxYjM5OWM0OTA5OTg2NzVmYTBmNTdhZTNlNzA1ZmZkZDcyY2Y5MGNj
14
- Y2E5ZTA4NjU4ZDU3ZTFmMTU0NGM1YzBlNmRjMTA2MWZmZjI5ZTFiNjRlMWNl
15
- YzY4N2U1ZDYzMjk2MjNhYmM4ZGYyYjRiNGJmYTE1NjYyYjg4MzM=
6
+ metadata.gz: ffbef3ab20d8b80eefb80661f0dbb166066019b571955f1a8ff7f7b98ef846453e52d5b5f67db896ee0c73d4ef90ef6b3ab3c2209d1b807da97e08c9cc22fb42
7
+ data.tar.gz: 2b512e857716fd73fd44589d97663090bd1a79e5ab45f7660aa27d5bc71fcc31a3c888cd5658da35b32fc31ef39e6885f975b67298c773bd2aaf5fcfba99454f
@@ -34,7 +34,9 @@ module Restify
34
34
  end
35
35
 
36
36
  def expand(params)
37
+ params = convert params
37
38
  variables = extract! params
39
+
38
40
  uri = @template.expand variables
39
41
  uri.query_values = params if params.any?
40
42
  uri
@@ -46,10 +48,20 @@ module Restify
46
48
  @context.request method, expand(params), data
47
49
  end
48
50
 
51
+ def convert(params)
52
+ params.each_pair.each_with_object({}) do |param, hash|
53
+ hash[param[0]] = convert_param param[1]
54
+ end
55
+ end
56
+
57
+ def convert_param(value)
58
+ return value.to_param.to_s if value.respond_to?(:to_param)
59
+ value
60
+ end
61
+
49
62
  def extract!(params)
50
63
  @template.variables.each_with_object({}) do |var, hash|
51
64
  if (value = params.delete(var) { params.delete(var.to_sym) { nil } })
52
- value = value.to_param if value.respond_to?(:to_param)
53
65
  hash[var] = value
54
66
  end
55
67
  end
@@ -2,7 +2,7 @@ module Restify
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STAGE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
8
8
 
@@ -24,12 +24,13 @@ describe Restify::Relation do
24
24
 
25
25
  it { is_expected.to be_a Addressable::URI }
26
26
 
27
- context 'with #to_param object' do
28
- class ParamObject
29
- def to_param
30
- 42
31
- end
27
+ class ParamObject
28
+ def to_param
29
+ 42
32
30
  end
31
+ end
32
+
33
+ context 'with #to_param object' do
33
34
 
34
35
  let(:params) { {id: ParamObject.new} }
35
36
 
@@ -41,5 +42,11 @@ describe Restify::Relation do
41
42
 
42
43
  it { expect(subject.to_s).to eq 'http://test.host/resource/5?abc=cde' }
43
44
  end
45
+
46
+ context 'with additional #to_param parameter' do
47
+ let(:params) { {id: '5', abc: ParamObject.new} }
48
+
49
+ it { expect(subject.to_s).to eq 'http://test.host/resource/5?abc=42' }
50
+ end
44
51
  end
45
52
  end
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.1.b48
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: obligation
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: addressable
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: em-http-request
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: hashie
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.3'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: multi_json
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rack
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '1.5'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.5'
111
111
  description: An experimental hypermedia REST client that uses parallel, keep-alive
@@ -140,10 +140,6 @@ files:
140
140
  - spec/restify/resource_spec.rb
141
141
  - spec/restify_spec.rb
142
142
  - spec/spec_helper.rb
143
- - vendor/bundle/ruby/2.1.0/bundler/gems/hashie-693de89e77eb/CHANGELOG.md
144
- - vendor/bundle/ruby/2.1.0/bundler/gems/hashie-693de89e77eb/LICENSE
145
- - vendor/bundle/ruby/2.1.0/bundler/gems/hashie-693de89e77eb/README.md
146
- - vendor/bundle/ruby/2.1.0/bundler/gems/hashie-693de89e77eb/hashie.gemspec
147
143
  homepage: https://github.com/jgraichen/restify
148
144
  licenses:
149
145
  - LGPLv3
@@ -154,17 +150,17 @@ require_paths:
154
150
  - lib
155
151
  required_ruby_version: !ruby/object:Gem::Requirement
156
152
  requirements:
157
- - - ! '>='
153
+ - - ">="
158
154
  - !ruby/object:Gem::Version
159
155
  version: '0'
160
156
  required_rubygems_version: !ruby/object:Gem::Requirement
161
157
  requirements:
162
- - - ! '>'
158
+ - - ">="
163
159
  - !ruby/object:Gem::Version
164
- version: 1.3.1
160
+ version: '0'
165
161
  requirements: []
166
162
  rubyforge_project:
167
- rubygems_version: 2.4.5
163
+ rubygems_version: 2.4.6
168
164
  signing_key:
169
165
  specification_version: 4
170
166
  summary: An experimental hypermedia REST client.
@@ -175,3 +171,4 @@ test_files:
175
171
  - spec/restify/resource_spec.rb
176
172
  - spec/restify_spec.rb
177
173
  - spec/spec_helper.rb
174
+ has_rdoc:
@@ -1,136 +0,0 @@
1
- ## Next Release
2
-
3
- * [#269](https://github.com/intridea/hashie/pull/272): Added Hashie::Extensions::DeepLocate - [@msievers](https://github.com/msievers).
4
- * [#270](https://github.com/intridea/hashie/pull/277): Fixed ArgumentError raised when using IndifferentAccess and HashWithIndifferentAccess - [@gardenofwine](https://github.com/gardenofwine).
5
- * [#281](https://github.com/intridea/hashie/pull/281): Added #reverse_merge to Mash to override ActiveSupport's version - [@mgold](https://github.com/mgold).
6
- * Your contribution here
7
-
8
- ## 3.4.0 (02/02/2014)
9
-
10
- * [#271](https://github.com/intridea/hashie/pull/271): Added ability to define defaults based on current hash - [@gregory](https://github.com/gregory).
11
- * [#247](https://github.com/intridea/hashie/pull/247): Fixed #stringify_keys and #symbolize_keys collision with ActiveSupport - [@bartoszkopinski](https://github.com/bartoszkopinski).
12
- * [#249](https://github.com/intridea/hashie/pull/249): SafeAssignment will now also protect hash-style assignments - [@jrochkind](https://github.com/jrochkind).
13
- * [#251](https://github.com/intridea/hashie/pull/251): Added block support to indifferent access #fetch - [@jgraichen](https://github.com/jgraichen).
14
- * [#252](https://github.com/intridea/hashie/pull/252): Added support for conditionally required Hashie::Dash attributes - [@ccashwell](https://github.com/ccashwell).
15
- * [#256](https://github.com/intridea/hashie/pull/256): Inherit key coercions - [@Erol](https://github.com/Erol).
16
- * [#259](https://github.com/intridea/hashie/pull/259): Fixed handling of default proc values in Mash - [@Erol](https://github.com/Erol).
17
- * [#260](https://github.com/intridea/hashie/pull/260): Added block support to Extensions::DeepMerge - [@galathius](https://github.com/galathius).
18
- * [#254](https://github.com/intridea/hashie/pull/254): Added public utility methods for stringify and symbolize keys - [@maxlinc](https://github.com/maxlinc).
19
- * [#261](https://github.com/intridea/hashie/pull/261): Fixed bug where Dash.property modifies argument object - [@d-tw](https://github.com/d-tw).
20
- * [#264](https://github.com/intridea/hashie/pull/264): Methods such as abc? return true/false with Hashie::Extensions::MethodReader - [@Zloy](https://github.com/Zloy).
21
- * [#269](https://github.com/intridea/hashie/pull/269): Add #extractable_options? so ActiveSupport Array#extract_options! can extract it - [@ridiculous](https://github.com/ridiculous).
22
-
23
- ## 3.3.2 (11/26/2014)
24
-
25
- * [#233](https://github.com/intridea/hashie/pull/233): Custom error messages for required properties in Hashie::Dash subclasses - [@joss](https://github.com/joss).
26
- * [#231](https://github.com/intridea/hashie/pull/231): Added support for coercion on class type that inherit from Hash - [@gregory](https://github.com/gregory).
27
- * [#228](https://github.com/intridea/hashie/pull/228): Made Hashie::Extensions::Parsers::YamlErbParser pass template filename to ERB - [@jperville](https://github.com/jperville).
28
- * [#224](https://github.com/intridea/hashie/pull/224): Merging Hashie::Mash now correctly only calls the block on duplicate values - [@amysutedja](https://github.com/amysutedja).
29
- * [#221](https://github.com/intridea/hashie/pull/221): Reduce amount of allocated objects on calls with suffixes in Hashie::Mash - [@kubum](https://github.com/kubum).
30
- * [#245](https://github.com/intridea/hashie/pull/245): Added Hashie::Extensions::MethodAccessWithOverride to autoloads - [@Fritzinger](https://github.com/Fritzinger).
31
-
32
- ## 3.3.1 (8/26/2014)
33
-
34
- * [#183](https://github.com/intridea/hashie/pull/183): Added Mash#load with YAML file support - [@gregory](https://github.com/gregory).
35
- * [#195](https://github.com/intridea/hashie/pull/195): Ensure that the same object is returned after injecting IndifferentAccess - [@michaelherold](https://github.com/michaelherold).
36
- * [#201](https://github.com/intridea/hashie/pull/201): Hashie::Trash transforms can be inherited - [@fobocaster](https://github.com/fobocaster).
37
- * [#189](https://github.com/intridea/hashie/pull/189): Added Rash#fetch - [@medcat](https://github.com/medcat).
38
- * [#200](https://github.com/intridea/hashie/pull/200): Improved coercion: primitives and error handling - [@maxlinc](https://github.com/maxlinc).
39
- * [#204](https://github.com/intridea/hashie/pull/204): Added Hashie::Extensions::MethodOverridingWriter and MethodAccessWithOverride - [@michaelherold](https://github.com/michaelherold).
40
- * [#205](http://github.com/intridea/hashie/pull/205): Added Hashie::Extensions::Mash::SafeAssignment - [@michaelherold](https://github.com/michaelherold).
41
- * [#206](http://github.com/intridea/hashie/pull/206): Fixed stack overflow from repetitively including coercion in subclasses - [@michaelherold](https://github.com/michaelherold).
42
- * [#207](http://github.com/intridea/hashie/pull/207): Fixed inheritance of transformations in Trash - [@fobocaster](https://github.com/fobocaster).
43
- * [#209](http://github.com/intridea/hashie/pull/209): Added Hashie::Extensions::DeepFind - [@michaelherold](https://github.com/michaelherold).
44
- * [#69](https://github.com/intridea/hashie/pull/69): Fixed regression in assigning multiple properties in Hashie::Trash - [@michaelherold](https://github.com/michaelherold), [@einzige](https://github.com/einzige), [@dblock](https://github.com/dblock).
45
-
46
- ## 3.2.0 (7/10/2014)
47
-
48
- * [#164](https://github.com/intridea/hashie/pull/164), [#165](https://github.com/intridea/hashie/pull/165), [#166](https://github.com/intridea/hashie/pull/166): Fixed stack overflow when coercing mashes that contain ActiveSupport::HashWithIndifferentAccess values - [@numinit](https://github.com/numinit), [@kgrz](https://github.com/kgrz).
49
- * [#177](https://github.com/intridea/hashie/pull/177): Added support for coercing enumerables and collections - [@gregory](https://github.com/gregory).
50
- * [#179](https://github.com/intridea/hashie/pull/179): Mash#values_at will convert each key before doing the lookup - [@nahiluhmot](https://github.com/nahiluhmot).
51
- * [#184](https://github.com/intridea/hashie/pull/184): Allow ranges on Rash to match all Numeric types - [@medcat](https://github.com/medcat).
52
- * [#187](https://github.com/intridea/hashie/pull/187): Automatically require version - [@medcat](https://github.com/medcat).
53
- * [#190](https://github.com/intridea/hashie/issues/190): Fixed `coerce_key` with `from` Trash feature and Coercion extension - [@gregory](https://github.com/gregory).
54
- * [#192](https://github.com/intridea/hashie/pull/192): Fixed StringifyKeys#stringify_keys! to recursively stringify keys of embedded ::Hash types - [@dblock](https://github.com/dblock).
55
-
56
- ## 3.1.0 (6/25/2014)
57
-
58
- * [#169](https://github.com/intridea/hashie/pull/169): Hash#to_hash will also convert nested objects that implement to_hash - [@gregory](https://github.com/gregory).
59
- * [#171](https://github.com/intridea/hashie/pull/171): Include Trash and Dash class name when raising `NoMethodError` - [@gregory](https://github.com/gregory).
60
- * [#172](https://github.com/intridea/hashie/pull/172): Added Dash and Trash#update_attributes! - [@gregory](https://github.com/gregory).
61
- * [#173](https://github.com/intridea/hashie/pull/173): Auto include Dash::IndifferentAccess when IndiferentAccess is included in Dash - [@gregory](https://github.com/gregory).
62
- * [#174](https://github.com/intridea/hashie/pull/174): Fixed `from` and `transform_with` Trash features when IndifferentAccess is included - [@gregory](https://github.com/gregory).
63
-
64
- ## 3.0.0 (6/3/2014)
65
-
66
- **Note:** This version introduces several backward incompatible API changes. See [UPGRADING](UPGRADING.md) for details.
67
-
68
- * [#150](https://github.com/intridea/hashie/pull/159): Handle nil intermediate object on deep fetch - [@stephenaument](https://github.com/stephenaument).
69
- * [#146](https://github.com/intridea/hashie/issues/146): Mash#respond_to? inconsistent with #method_missing and does not respond to #permitted? - [@dblock](https://github.com/dblock).
70
- * [#152](https://github.com/intridea/hashie/pull/152): Do not convert keys to String in Hashie::Dash and Hashie::Trash, use Hashie::Extensions::Dash::IndifferentAccess to achieve backward compatible behavior - [@dblock](https://github.com/dblock).
71
- * [#152](https://github.com/intridea/hashie/pull/152): Do not automatically stringify keys in Hashie::Hash#to_hash, pass `:stringify_keys` to achieve backward compatible behavior - [@dblock](https://github.com/dblock).
72
- * [#148](https://github.com/intridea/hashie/pull/148): Consolidated Hashie::Hash#stringify_keys implementation - [@dblock](https://github.com/dblock).
73
- * [#149](https://github.com/intridea/hashie/issues/149): Allow IgnoreUndeclared and DeepMerge to be used with undeclared properties - [@jhaesus](https://github.com/jhaesus).
74
-
75
- ## 2.1.1 (4/12/2014)
76
-
77
- * [#144](https://github.com/intridea/hashie/issues/144): Fixed regression invoking `to_hash` with no parameters - [@mbleigh](https://github.com/mbleigh).
78
-
79
- ## 2.1.0 (4/6/2014)
80
-
81
- * [#134](https://github.com/intridea/hashie/pull/134): Add deep_fetch extension for nested access - [@tylerdooling](https://github.com/tylerdooling).
82
- * Removed support for Ruby 1.8.7 - [@dblock](https://github.com/dblock).
83
- * Ruby style now enforced with Rubocop - [@dblock](https://github.com/dblock).
84
- * [#138](https://github.com/intridea/hashie/pull/138): Added Hashie#Rash, a hash whose keys can be regular expressions or ranges - [@epitron](https://github.com/epitron).
85
- * [#131](https://github.com/intridea/hashie/pull/131): Added IgnoreUndeclared, an extension to silently ignore undeclared properties at intialization - [@righi](https://github.com/righi).
86
- * [#136](https://github.com/intridea/hashie/issues/136): Removed Hashie::Extensions::Structure - [@markiz](https://github.com/markiz).
87
- * [#107](https://github.com/intridea/hashie/pull/107): Fixed excessive value conversions, poor performance of deep merge in Hashie::Mash - [@davemitchell](https://github.com/dblock), [@dblock](https://github.com/dblock).
88
- * [#69](https://github.com/intridea/hashie/issues/69): Fixed assigning multiple properties in Hashie::Trash - [@einzige](https://github.com/einzige).
89
- * [#100](https://github.com/intridea/hashie/pull/100): IndifferentAccess#store will respect indifference - [@jrochkind](https://github.com/jrochkind).
90
- * [#103](https://github.com/intridea/hashie/pull/103): Fixed support for Hashie::Dash properties that end in bang - [@thedavemarshall](https://github.com/thedavemarshall).
91
- * [89](https://github.com/intridea/hashie/issues/89): Do not respond to every method with suffix in Hashie::Mash, fixes Rails strong_parameters - [@Maxim-Filimonov](https://github.com/Maxim-Filimonov).
92
- * [#110](https://github.com/intridea/hashie/pull/110): Correctly use Hash#default from Mash#method_missing - [@ryansouza](https://github.com/ryansouza).
93
- * [#120](https://github.com/intridea/hashie/pull/120): Pass options to recursive to_hash calls - [@pwillett](https://github.com/pwillett).
94
- * [#113](https://github.com/intridea/hashie/issues/113): Fixed Hash#merge with Hashie::Dash - [@spencer1248](https://github.com/spencer1248).
95
- * [#99](https://github.com/intridea/hashie/issues/99): Hash#deep_merge raises errors when it encounters integers - [@defsprite](https://github.com/defsprite).
96
- * [#133](https://github.com/intridea/hashie/pull/133): Fixed Hash##to_hash with symbolize_keys - [@mhuggins](https://github.com/mhuggins).
97
- * [#130](https://github.com/intridea/hashie/pull/130): IndifferentAccess now works without MergeInitializer - [@npj](https://github.com/npj).
98
- * [#111](https://github.com/intridea/hashie/issues/111): Trash#translations correctly maps original to translated names - [@artm](https://github.com/artm).
99
- * [#129](https://github.com/intridea/hashie/pull/129): Added Trash#permitted_input_keys and inverse_translations - [@artm](https://github.com/artm).
100
-
101
- ## 2.0.5
102
-
103
- * [#96](https://github.com/intridea/hashie/pull/96): Make coercion work better with non-symbol keys in Hashie::Mash - [@wapcaplet](https://github.com/wapcaplet).
104
-
105
- ## 2.0.4
106
-
107
- * [#04](https://github.com/intridea/hashie/pull/94): Make #fetch method consistent with normal Hash - [@markiz](https://github.com/markiz).
108
- * [#90](https://github.com/intridea/hashie/pull/90): Various doc tweaks - [@craiglittle](https://github.com/craiglittle).
109
-
110
- ## 2.0.3
111
-
112
- * [#88](https://github.com/intridea/hashie/pull/88): Hashie::Mash.new(abc: true).respond_to?(:abc?) works - [@7even](https://github.com/7even).
113
- * [#68](https://github.com/intridea/hashie/pull/68): Fix #replace - [@jimeh](https://github.com/jimeh).
114
-
115
- ## 2.0.2
116
-
117
- * [#85](https://github.com/intridea/hashie/pull/85): adding symbolize_keys back to to_hash - [@cromulus](https://github.com/cromulus).
118
-
119
- ## 2.0.1
120
-
121
- * [#81](https://github.com/intridea/hashie/pull/81): remove Mash#object_id override - [@matschaffer](https://github.com/matschaffer).
122
- * Gem cleanup: removed VERSION, Gemfile.lock [@jch](https://github.com/jch), [@mbleigh](https://github.com/mbleigh).
123
-
124
- ## 2.0.0
125
-
126
- * [#72](https://github.com/intridea/hashie/pull/72): Updated gemspec with license info - [@jordimassaguerpla](https://github.com/jordimassaguerpla).
127
- * [#27](https://github.com/intridea/hashie/pull/27): Initialized with merge coerces values - [@mattfawcett](https://github.com/mattfawcett).
128
- * [#28](https://github.com/intridea/hashie/pull/28): Hashie::Extensions::Coercion coerce_keys takes arguments - [@mattfawcett](https://github.com/mattfawcett).
129
- * [#39](https://github.com/intridea/hashie/pull/39): Trash removes translated values on initialization - [@sleverbor](https://github.com/sleverbor).
130
- * [#66](https://github.com/intridea/hashie/pull/66): Mash#fetch works with symbol or string keys - [@arthwood](https://github.com/arthwood).
131
- * [#49](https://github.com/intridea/hashie/pull/49): Hashie::Hash inherits from ::Hash to avoid ambiguity - [@meh](https://github.com/meh), [@orend](https://github.com/orend).
132
- * [#62](https://github.com/intridea/hashie/pull/62): update respond_to? method signature to match ruby core definition - [@dlupu](https://github.com/dlupu).
133
- * [#41](https://github.com/intridea/hashie/pull/41): DeepMerge extension - [@nashby](https://github.com/nashby).
134
- * [#63](https://github.com/intridea/hashie/pull/63): Dash defaults are dup'ed before assigned - [@ohrite](https://github.com/ohrite).
135
- * [#77](https://github.com/intridea/hashie/pull/77): Remove id, type, and object_id as special allowable keys [@jch](https://github.com/jch).
136
- * [#78](https://github.com/intridea/hashie/pull/78): Merge and update accepts a block - [@jch](https://github.com/jch).
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Intridea, Inc., and Contributors
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,630 +0,0 @@
1
- # Hashie
2
-
3
- [![Join the chat at https://gitter.im/intridea/hashie](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/intridea/hashie?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
-
5
- [![Gem Version](http://img.shields.io/gem/v/hashie.svg)](http://badge.fury.io/rb/hashie)
6
- [![Build Status](http://img.shields.io/travis/intridea/hashie.svg)](https://travis-ci.org/intridea/hashie)
7
- [![Dependency Status](https://gemnasium.com/intridea/hashie.svg)](https://gemnasium.com/intridea/hashie)
8
- [![Code Climate](https://codeclimate.com/github/intridea/hashie.svg)](https://codeclimate.com/github/intridea/hashie)
9
- [![Coverage Status](https://codeclimate.com/github/intridea/hashie/badges/coverage.svg)](https://codeclimate.com/github/intridea/hashie)
10
-
11
- Hashie is a growing collection of tools that extend Hashes and make them more useful.
12
-
13
- ## Installation
14
-
15
- Hashie is available as a RubyGem:
16
-
17
- ```bash
18
- $ gem install hashie
19
- ```
20
-
21
- ## Upgrading
22
-
23
- You're reading the documentation for the next release of Hashie, which should be 3.3.2. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version. The current stable release is [3.3.1](https://github.com/intridea/hashie/blob/v3.3.1/README.md).
24
-
25
- ## Hash Extensions
26
-
27
- The library is broken up into a number of atomically includeable Hash extension modules as described below. This provides maximum flexibility for users to mix and match functionality while maintaining feature parity with earlier versions of Hashie.
28
-
29
- Any of the extensions listed below can be mixed into a class by `include`-ing `Hashie::Extensions::ExtensionName`.
30
-
31
- ### Coercion
32
-
33
- Coercions allow you to set up "coercion rules" based either on the key or the value type to massage data as it's being inserted into the Hash. Key coercions might be used, for example, in lightweight data modeling applications such as an API client:
34
-
35
- ```ruby
36
- class Tweet < Hash
37
- include Hashie::Extensions::Coercion
38
- coerce_key :user, User
39
- end
40
-
41
- user_hash = { name: "Bob" }
42
- Tweet.new(user: user_hash)
43
- # => automatically calls User.coerce(user_hash) or
44
- # User.new(user_hash) if that isn't present.
45
- ```
46
-
47
- Value coercions, on the other hand, will coerce values based on the type of the value being inserted. This is useful if you are trying to build a Hash-like class that is self-propagating.
48
-
49
- ```ruby
50
- class SpecialHash < Hash
51
- include Hashie::Extensions::Coercion
52
- coerce_value Hash, SpecialHash
53
-
54
- def initialize(hash = {})
55
- super
56
- hash.each_pair do |k,v|
57
- self[k] = v
58
- end
59
- end
60
- end
61
- ```
62
-
63
- ### Coercing Collections
64
-
65
- ```ruby
66
- class Tweet < Hash
67
- include Hashie::Extensions::Coercion
68
- coerce_key :mentions, Array[User]
69
- coerce_key :friends, Set[User]
70
- end
71
-
72
- user_hash = { name: "Bob" }
73
- mentions_hash= [user_hash, user_hash]
74
- friends_hash = [user_hash]
75
- tweet = Tweet.new(mentions: mentions_hash, friends: friends_hash)
76
- # => automatically calls User.coerce(user_hash) or
77
- # User.new(user_hash) if that isn't present on each element of the array
78
-
79
- tweet.mentions.map(&:class) # => [User, User]
80
- tweet.friends.class # => Set
81
- ```
82
-
83
- ### Coercing Hashes
84
-
85
- ```ruby
86
- class Relation
87
- def initialize(string)
88
- @relation = string
89
- end
90
- end
91
-
92
- class Tweet < Hash
93
- include Hashie::Extensions::Coercion
94
- coerce_key :relations, Hash[User => Relation]
95
- end
96
-
97
- user_hash = { name: "Bob" }
98
- relations_hash= { user_hash => "father", user_hash => "friend" }
99
- tweet = Tweet.new(relations: relations_hash)
100
- tweet.relations.map { |k,v| [k.class, v.class] } # => [[User, Relation], [User, Relation]]
101
- tweet.relations.class # => Hash
102
-
103
- # => automatically calls User.coerce(user_hash) on each key
104
- # and Relation.new on each value since Relation doesn't define the `coerce` class method
105
- ```
106
-
107
- ### Coercing Core Types
108
-
109
- Hashie handles coercion to the following by using standard conversion methods:
110
-
111
- | type | method |
112
- |----------|----------|
113
- | Integer | `#to_i` |
114
- | Float | `#to_f` |
115
- | Complex | `#to_c` |
116
- | Rational | `#to_r` |
117
- | String | `#to_s` |
118
- | Symbol | `#to_sym`|
119
-
120
- **Note**: The standard Ruby conversion methods are less strict than you may assume. For example, `:foo.to_i` raises an error but `"foo".to_i` returns 0.
121
-
122
- You can also use coerce from the following supertypes with `coerce_value`:
123
- - Integer
124
- - Numeric
125
-
126
- Hashie does not have built-in support for coercion boolean values, since Ruby does not have a built-in boolean type or standard method for to a boolean. You can coerce to booleans using a custom proc.
127
-
128
- ### Coercion Proc
129
-
130
- You can use a custom coercion proc on either `#coerce_key` or `#coerce_value`. This is useful for coercing to booleans or other simple types without creating a new class and `coerce` method. For example:
131
-
132
- ```ruby
133
- class Tweet < Hash
134
- include Hashie::Extensions::Coercion
135
- coerce_key :retweeted, ->(v) do
136
- case v
137
- when String
138
- return !!(v =~ /^(true|t|yes|y|1)$/i)
139
- when Numeric
140
- return !v.to_i.zero?
141
- else
142
- return v == true
143
- end
144
- end
145
- end
146
- ```
147
-
148
- ### KeyConversion
149
-
150
- The KeyConversion extension gives you the convenience methods of `symbolize_keys` and `stringify_keys` along with their bang counterparts. You can also include just stringify or just symbolize with `Hashie::Extensions::StringifyKeys` or `Hashie::Extensions::SymbolizeKeys`.
151
-
152
- Hashie also has a utility method for converting keys on a Hash without a mixin:
153
-
154
- ```ruby
155
- Hashie.symbolize_keys! hash # => Symbolizes keys of hash.
156
- Hashie.symbolize_keys hash # => Returns a copy of hash with keys symbolized.
157
- Hashie.stringify_keys hash # => Stringifies keys of hash.
158
- Hashie.stringify_keys hash # => Returns a copy of hash with keys stringified.
159
- ```
160
-
161
- ### MergeInitializer
162
-
163
- The MergeInitializer extension simply makes it possible to initialize a Hash subclass with another Hash, giving you a quick short-hand.
164
-
165
- ### MethodAccess
166
-
167
- The MethodAccess extension allows you to quickly build method-based reading, writing, and querying into your Hash descendant. It can also be included as individual modules, i.e. `Hashie::Extensions::MethodReader`, `Hashie::Extensions::MethodWriter` and `Hashie::Extensions::MethodQuery`.
168
-
169
- ```ruby
170
- class MyHash < Hash
171
- include Hashie::Extensions::MethodAccess
172
- end
173
-
174
- h = MyHash.new
175
- h.abc = 'def'
176
- h.abc # => 'def'
177
- h.abc? # => true
178
- ```
179
-
180
- ### MethodAccessWithOverride
181
-
182
- The MethodAccessWithOverride extension is like the MethodAccess extension, except that it allows you to override Hash methods. It aliases any overridden method with two leading underscores. To include only this overriding functionality, you can include the single module `Hashie::Extensions::MethodOverridingWriter`.
183
-
184
- ```ruby
185
- class MyHash < Hash
186
- include Hashie::Extensions::MethodAccess
187
- end
188
-
189
- class MyOverridingHash < Hash
190
- include Hashie::Extensions::MethodAccessWithOverride
191
- end
192
-
193
- non_overriding = MyHash.new
194
- non_overriding.zip = 'a-dee-doo-dah'
195
- non_overriding.zip #=> [[['zip', 'a-dee-doo-dah']]]
196
-
197
- overriding = MyOverridingHash.new
198
- overriding.zip = 'a-dee-doo-dah'
199
- overriding.zip #=> 'a-dee-doo-dah'
200
- overriding.__zip #=> [[['zip', 'a-dee-doo-dah']]]
201
- ```
202
-
203
- ### IndifferentAccess
204
-
205
- This extension can be mixed in to instantly give you indifferent access to your Hash subclass. This works just like the params hash in Rails and other frameworks where whether you provide symbols or strings to access keys, you will get the same results.
206
-
207
- A unique feature of Hashie's IndifferentAccess mixin is that it will inject itself recursively into subhashes *without* reinitializing the hash in question. This means you can safely merge together indifferent and non-indifferent hashes arbitrarily deeply without worrying about whether you'll be able to `hash[:other][:another]` properly.
208
-
209
- ### IgnoreUndeclared
210
-
211
- This extension can be mixed in to silently ignore undeclared properties on initialization instead of raising an error. This is useful when using a Trash to capture a subset of a larger hash.
212
-
213
- ```ruby
214
- class Person < Trash
215
- include Hashie::Extensions::IgnoreUndeclared
216
- property :first_name
217
- property :last_name
218
- end
219
-
220
- user_data = {
221
- first_name: 'Freddy',
222
- last_name: 'Nostrils',
223
- email: 'freddy@example.com'
224
- }
225
-
226
- p = Person.new(user_data) # 'email' is silently ignored
227
-
228
- p.first_name # => 'Freddy'
229
- p.last_name # => 'Nostrils'
230
- p.email # => NoMethodError
231
- ```
232
-
233
- ### DeepMerge
234
-
235
- This extension allow you to easily include a recursive merging
236
- system to any Hash descendant:
237
-
238
- ```ruby
239
- class MyHash < Hash
240
- include Hashie::Extensions::DeepMerge
241
- end
242
-
243
- h1 = MyHash[{ x: { y: [4,5,6] }, z: [7,8,9] }]
244
- h2 = MyHash[{ x: { y: [7,8,9] }, z: "xyz" }]
245
-
246
- h1.deep_merge(h2) # => { x: { y: [7, 8, 9] }, z: "xyz" }
247
- h2.deep_merge(h1) # => { x: { y: [4, 5, 6] }, z: [7, 8, 9] }
248
- ```
249
-
250
- Like with Hash#merge in the standard library, a block can be provided to merge values:
251
-
252
- ```ruby
253
- class MyHash < Hash
254
- include Hashie::Extensions::DeepMerge
255
- end
256
-
257
- h1 = MyHash[{ a: 100, b: 200, c: { c1: 100 } }]
258
- h2 = MyHash[{ b: 250, c: { c1: 200 } }]
259
-
260
- h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
261
- # => { a: 100, b: 450, c: { c1: 300 } }
262
- ```
263
-
264
-
265
- ### DeepFetch
266
-
267
- This extension can be mixed in to provide for safe and concise retrieval of deeply nested hash values. In the event that the requested key does not exist a block can be provided and its value will be returned.
268
-
269
- Though this is a hash extension, it conveniently allows for arrays to be present in the nested structure. This feature makes the extension particularly useful for working with JSON API responses.
270
-
271
- ```ruby
272
- user = {
273
- name: { first: 'Bob', last: 'Boberts' },
274
- groups: [
275
- { name: 'Rubyists' },
276
- { name: 'Open source enthusiasts' }
277
- ]
278
- }
279
-
280
- user.extend Hashie::Extensions::DeepFetch
281
-
282
- user.deep_fetch :name, :first # => 'Bob'
283
- user.deep_fetch :name, :middle # => 'KeyError: Could not fetch middle'
284
-
285
- # using a default block
286
- user.deep_fetch(:name, :middle) { |key| 'default' } # => 'default'
287
-
288
- # a nested array
289
- user.deep_fetch :groups, 1, :name # => 'Open source enthusiasts'
290
- ```
291
-
292
- ### DeepFind
293
-
294
- This extension can be mixed in to provide for concise searching for keys within a deeply nested hash.
295
-
296
- It can also search through any Enumerable contained within the hash for objects with the specified key.
297
-
298
- Note: The searches are depth-first, so it is not guaranteed that a shallowly nested value will be found before a deeply nested value.
299
-
300
- ```ruby
301
- user = {
302
- name: { first: 'Bob', last: 'Boberts' },
303
- groups: [
304
- { name: 'Rubyists' },
305
- { name: 'Open source enthusiasts' }
306
- ]
307
- }
308
-
309
- user.extend Hashie::Extensions::DeepFind
310
-
311
- user.deep_find(:name) #=> { first: 'Bob', last: 'Boberts' }
312
- user.deep_detect(:name) #=> { first: 'Bob', last: 'Boberts' }
313
-
314
- user.deep_find_all(:name) #=> [{ first: 'Bob', last: 'Boberts' }, 'Rubyists', 'Open source enthusiasts']
315
- user.deep_select(:name) #=> [{ first: 'Bob', last: 'Boberts' }, 'Rubyists', 'Open source enthusiasts']
316
- ```
317
-
318
- ### DeepLocate
319
-
320
- This extension can be mixed in to provide a depth first search based search for enumerables matching a given comparator callable.
321
-
322
- It returns all enumerables which contain at least one element, for which the given comparator returns ```true```.
323
-
324
- Because the container objects are returned, the result elements can be modified in place. This way, one can perform modifications on deeply nested hashes without the need to know the exact paths.
325
-
326
- ```ruby
327
-
328
- books = [
329
- {
330
- title: "Ruby for beginners",
331
- pages: 120
332
- },
333
- {
334
- title: "CSS for intermediates",
335
- pages: 80
336
- },
337
- {
338
- title: "Collection of ruby books",
339
- books: [
340
- {
341
- title: "Ruby for the rest of us",
342
- pages: 576
343
- }
344
- ]
345
- }
346
- ]
347
-
348
- books.extend(Hashie::Extensions::DeepLocate)
349
-
350
- # for ruby 1.9 leave *no* space between the lambda rocket and the braces
351
- # http://ruby-journal.com/becareful-with-space-in-lambda-hash-rocket-syntax-between-ruby-1-dot-9-and-2-dot-0/
352
-
353
- books.deep_locate -> (key, value, object) { key == :title && value.include?("Ruby") }
354
- # => [{:title=>"Ruby for beginners", :pages=>120}, {:title=>"Ruby for the rest of us", :pages=>576}]
355
-
356
- books.deep_locate -> (key, value, object) { key == :pages && value <= 120 }
357
- # => [{:title=>"Ruby for beginners", :pages=>120}, {:title=>"CSS for intermediates", :pages=>80}]
358
- ```
359
-
360
- ## Mash
361
-
362
- Mash is an extended Hash that gives simple pseudo-object functionality that can be built from hashes and easily extended. It is intended to give the user easier access to the objects within the Mash through a property-like syntax, while still retaining all Hash functionality.
363
-
364
- ### Example:
365
-
366
- ```ruby
367
- mash = Hashie::Mash.new
368
- mash.name? # => false
369
- mash.name # => nil
370
- mash.name = "My Mash"
371
- mash.name # => "My Mash"
372
- mash.name? # => true
373
- mash.inspect # => <Hashie::Mash name="My Mash">
374
-
375
- mash = Hashie::Mash.new
376
- # use bang methods for multi-level assignment
377
- mash.author!.name = "Michael Bleigh"
378
- mash.author # => <Hashie::Mash name="Michael Bleigh">
379
-
380
- mash = Hashie::Mash.new
381
- # use under-bang methods for multi-level testing
382
- mash.author_.name? # => false
383
- mash.inspect # => <Hashie::Mash>
384
- ```
385
-
386
- **Note:** The `?` method will return false if a key has been set to false or nil. In order to check if a key has been set at all, use the `mash.key?('some_key')` method instead.
387
-
388
- Please note that a Mash will not override methods through the use of the property-like syntax. This can lead to confusion if you expect to be able to access a Mash value through the property-like syntax for a key that conflicts with a method name. However, it protects users of your library from the unexpected behavior of those methods being overridden behind the scenes.
389
-
390
- ### Example:
391
-
392
- ```ruby
393
- mash = Hashie::Mash.new
394
- mash.name = "My Mash"
395
- mash.zip = "Method Override?"
396
- mash.zip # => [[["name", "My Mash"]], [["zip", "Method Override?"]]]
397
- ```
398
-
399
- Mash allows you also to transform any files into a Mash objects.
400
-
401
- ### Example:
402
-
403
- ```yml
404
- #/etc/config/settings/twitter.yml
405
- development:
406
- api_key: 'api_key'
407
- production:
408
- api_key: <%= ENV['API_KEY'] %> #let's say that ENV['API_KEY'] is set to 'abcd'
409
- ```
410
-
411
- ```ruby
412
- mash = Mash.load('settings/twitter.yml')
413
- mash.development.api_key # => 'localhost'
414
- mash.development.api_key = "foo" # => <# RuntimeError can't modify frozen ...>
415
- mash.development.api_key? # => true
416
- ```
417
-
418
- You can access a Mash from another class:
419
-
420
- ```ruby
421
- mash = Mash.load('settings/twitter.yml')[ENV['RACK_ENV']]
422
- Twitter.extend mash.to_module # NOTE: if you want another name than settings, call: to_module('my_settings')
423
- Twitter.settings.api_key # => 'abcd'
424
- ```
425
-
426
- You can use another parser (by default: YamlErbParser):
427
-
428
- ```
429
- #/etc/data/user.csv
430
- id | name | lastname
431
- ---|------------- | -------------
432
- 1 |John | Doe
433
- 2 |Laurent | Garnier
434
- ```
435
-
436
- ```ruby
437
- mash = Mash.load('data/user.csv', parser: MyCustomCsvParser)
438
- # => { 1 => { name: 'John', lastname: 'Doe'}, 2 => { name: 'Laurent', lastname: 'Garnier' } }
439
- mash[1] #=> { name: 'John', lastname: 'Doe' }
440
- ```
441
-
442
- ### Mash Extension: SafeAssignment
443
-
444
- This extension can be mixed into a Mash to guard the attempted overwriting of methods by property setters. When mixed in, the Mash will raise an `ArgumentError` if you attempt to write a property with the same name as an existing method.
445
-
446
- #### Example:
447
-
448
- ```ruby
449
- class SafeMash < ::Hashie::Mash
450
- include Hashie::Extensions::Mash::SafeAssignment
451
- end
452
-
453
- safe_mash = SafeMash.new
454
- safe_mash.zip = 'Test' # => ArgumentError
455
- safe_mash[:zip] = 'test' # => still ArgumentError
456
- ```
457
-
458
- ## Dash
459
-
460
- Dash is an extended Hash that has a discrete set of defined properties and only those properties may be set on the hash. Additionally, you can set defaults for each property. You can also flag a property as required. Required properties will raise an exception if unset. Another option is message for required properties, which allow you to add custom messages for required property.
461
-
462
- You can also conditionally require certain properties by passing a Proc or Symbol. If a Proc is provided, it will be run in the context of the Dash instance. If a Symbol is provided, the value returned for the property or method of the same name will be evaluated. The property will be required if the result of the conditional is truthy.
463
-
464
- ### Example:
465
-
466
- ```ruby
467
- class Person < Hashie::Dash
468
- property :name, required: true
469
- property :age, required: true, message: 'must be set.'
470
- property :email
471
- property :phone, required: -> { email.nil? }, message: 'is required if email is not set.'
472
- property :pants, required: :weekday?, message: 'are only required on weekdays.'
473
- property :occupation, default: 'Rubyist'
474
-
475
- def weekday?
476
- [ Time.now.saturday?, Time.now.sunday? ].none?
477
- end
478
- end
479
-
480
- p = Person.new # => ArgumentError: The property 'name' is required for this Dash.
481
- p = Person.new(name: 'Bob') # => ArgumentError: The property 'age' must be set.
482
-
483
- p = Person.new(name: "Bob", age: 18)
484
- p.name # => 'Bob'
485
- p.name = nil # => ArgumentError: The property 'name' is required for this Dash.
486
- p.age # => 18
487
- p.age = nil # => ArgumentError: The property 'age' must be set.
488
- p.email = 'abc@def.com'
489
- p.occupation # => 'Rubyist'
490
- p.email # => 'abc@def.com'
491
- p[:awesome] # => NoMethodError
492
- p[:occupation] # => 'Rubyist'
493
- p.update_attributes!(name: 'Trudy', occupation: 'Evil')
494
- p.occupation # => 'Evil'
495
- p.name # => 'Trudy'
496
- p.update_attributes!(occupation: nil)
497
- p.occupation # => 'Rubyist'
498
- ```
499
-
500
- Properties defined as symbols are not the same thing as properties defined as strings.
501
-
502
- ### Example:
503
-
504
- ```ruby
505
- class Tricky < Hashie::Dash
506
- property :trick
507
- property 'trick'
508
- end
509
-
510
- p = Tricky.new(trick: 'one', 'trick' => 'two')
511
- p.trick # => 'one', always symbol version
512
- p[:trick] # => 'one'
513
- p['trick'] # => 'two'
514
- ```
515
-
516
- Note that accessing a property as a method always uses the symbol version.
517
-
518
- ```ruby
519
- class Tricky < Hashie::Dash
520
- property 'trick'
521
- end
522
-
523
- p = Tricky.new('trick' => 'two')
524
- p.trick # => NoMethodError
525
- ```
526
-
527
- ### Mash and Rails 4 Strong Parameters
528
-
529
- To enable compatibility with Rails 4 use the [hashie_rails](http://rubygems.org/gems/hashie_rails) gem.
530
-
531
- ## Trash
532
-
533
- A Trash is a Dash that allows you to translate keys on initialization. It is used like so:
534
-
535
- ```ruby
536
- class Person < Hashie::Trash
537
- property :first_name, from: :firstName
538
- end
539
- ```
540
-
541
- This will automatically translate the <tt>firstName</tt> key to <tt>first_name</tt>
542
- when it is initialized using a hash such as through:
543
-
544
- ```ruby
545
- Person.new(firstName: 'Bob')
546
- ```
547
-
548
- Trash also supports translations using lambda, this could be useful when dealing with external API's. You can use it in this way:
549
-
550
- ```ruby
551
- class Result < Hashie::Trash
552
- property :id, transform_with: lambda { |v| v.to_i }
553
- property :created_at, from: :creation_date, with: lambda { |v| Time.parse(v) }
554
- end
555
- ```
556
-
557
- this will produce the following
558
-
559
- ```ruby
560
- result = Result.new(id: '123', creation_date: '2012-03-30 17:23:28')
561
- result.id.class # => Fixnum
562
- result.created_at.class # => Time
563
- ```
564
-
565
- ## Clash
566
-
567
- Clash is a Chainable Lazy Hash that allows you to easily construct complex hashes using method notation chaining. This will allow you to use a more action-oriented approach to building options hashes.
568
-
569
- Essentially, a Clash is a generalized way to provide much of the same kind of "chainability" that libraries like Arel or Rails 2.x's named_scopes provide.
570
-
571
- ### Example:
572
-
573
- ```ruby
574
- c = Hashie::Clash.new
575
- c.where(abc: 'def').order(:created_at)
576
- c # => { where: { abc: 'def' }, order: :created_at }
577
-
578
- # You can also use bang notation to chain into sub-hashes,
579
- # jumping back up the chain with _end!
580
- c = Hashie::Clash.new
581
- c.where!.abc('def').ghi(123)._end!.order(:created_at)
582
- c # => { where: { abc: 'def', ghi: 123 }, order: :created_at }
583
-
584
- # Multiple hashes are merged automatically
585
- c = Hashie::Clash.new
586
- c.where(abc: 'def').where(hgi: 123)
587
- c # => { where: { abc: 'def', hgi: 123 } }
588
- ```
589
-
590
- ## Rash
591
-
592
- Rash is a Hash whose keys can be Regexps or Ranges, which will map many input keys to a value.
593
-
594
- A good use case for the Rash is an URL router for a web framework, where URLs need to be mapped to actions; the Rash's keys match URL patterns, while the values call the action which handles the URL.
595
-
596
- If the Rash's value is a `proc`, the `proc` will be automatically called with the regexp's MatchData (matched groups) as a block argument.
597
-
598
- ### Example:
599
-
600
- ```ruby
601
-
602
- # Mapping names to appropriate greetings
603
- greeting = Hashie::Rash.new( /^Mr./ => "Hello sir!", /^Mrs./ => "Evening, madame." )
604
- greeting["Mr. Steve Austin"] # => "Hello sir!"
605
- greeting["Mrs. Steve Austin"] # => "Evening, madame."
606
-
607
- # Mapping statements to saucy retorts
608
- mapper = Hashie::Rash.new(
609
- /I like (.+)/ => proc { |m| "Who DOESN'T like #{m[1]}?!" },
610
- /Get off my (.+)!/ => proc { |m| "Forget your #{m[1]}, old man!" }
611
- )
612
- mapper["I like traffic lights"] # => "Who DOESN'T like traffic lights?!"
613
- mapper["Get off my lawn!"] # => "Forget your lawn, old man!"
614
- ```
615
-
616
- ### Auto-optimized
617
-
618
- **Note:** The Rash is automatically optimized every 500 accesses (which means that it sorts the list of Regexps, putting the most frequently matched ones at the beginning).
619
-
620
- If this value is too low or too high for your needs, you can tune it by setting: `rash.optimize_every = n`.
621
-
622
- ## Contributing
623
-
624
- See [CONTRIBUTING.md](CONTRIBUTING.md)
625
-
626
- ## Copyright
627
-
628
- Copyright (c) 2009-2014 Intridea, Inc. (http://intridea.com/) and [contributors](https://github.com/intridea/hashie/graphs/contributors).
629
-
630
- MIT License. See [LICENSE](LICENSE) for details.
@@ -1,35 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # stub: hashie 3.4.0 ruby lib
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "hashie"
6
- s.version = "3.4.0"
7
-
8
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
- s.require_paths = ["lib"]
10
- s.authors = ["Michael Bleigh", "Jerry Cheung"]
11
- s.date = "2015-03-10"
12
- s.description = "Hashie is a collection of classes and mixins that make hashes more powerful."
13
- s.email = ["michael@intridea.com", "jollyjerry@gmail.com"]
14
- s.files = [".yardopts", "CHANGELOG.md", "CONTRIBUTING.md", "LICENSE", "README.md", "Rakefile", "UPGRADING.md", "hashie.gemspec", "lib/hashie.rb", "lib/hashie/clash.rb", "lib/hashie/dash.rb", "lib/hashie/extensions/coercion.rb", "lib/hashie/extensions/dash/indifferent_access.rb", "lib/hashie/extensions/deep_fetch.rb", "lib/hashie/extensions/deep_find.rb", "lib/hashie/extensions/deep_locate.rb", "lib/hashie/extensions/deep_merge.rb", "lib/hashie/extensions/ignore_undeclared.rb", "lib/hashie/extensions/indifferent_access.rb", "lib/hashie/extensions/key_conversion.rb", "lib/hashie/extensions/mash/safe_assignment.rb", "lib/hashie/extensions/merge_initializer.rb", "lib/hashie/extensions/method_access.rb", "lib/hashie/extensions/parsers/yaml_erb_parser.rb", "lib/hashie/extensions/pretty_inspect.rb", "lib/hashie/extensions/stringify_keys.rb", "lib/hashie/extensions/symbolize_keys.rb", "lib/hashie/hash.rb", "lib/hashie/mash.rb", "lib/hashie/rash.rb", "lib/hashie/trash.rb", "lib/hashie/version.rb", "spec/hashie/clash_spec.rb", "spec/hashie/dash_spec.rb", "spec/hashie/extensions/autoload_spec.rb", "spec/hashie/extensions/coercion_spec.rb", "spec/hashie/extensions/dash/indifferent_access_spec.rb", "spec/hashie/extensions/deep_fetch_spec.rb", "spec/hashie/extensions/deep_find_spec.rb", "spec/hashie/extensions/deep_locate_spec.rb", "spec/hashie/extensions/deep_merge_spec.rb", "spec/hashie/extensions/ignore_undeclared_spec.rb", "spec/hashie/extensions/indifferent_access_spec.rb", "spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb", "spec/hashie/extensions/key_conversion_spec.rb", "spec/hashie/extensions/mash/safe_assignment_spec.rb", "spec/hashie/extensions/merge_initializer_spec.rb", "spec/hashie/extensions/method_access_spec.rb", "spec/hashie/extensions/stringify_keys_spec.rb", "spec/hashie/extensions/symbolize_keys_spec.rb", "spec/hashie/hash_spec.rb", "spec/hashie/mash_spec.rb", "spec/hashie/parsers/yaml_erb_parser_spec.rb", "spec/hashie/rash_spec.rb", "spec/hashie/trash_spec.rb", "spec/hashie/version_spec.rb", "spec/spec_helper.rb", "spec/support/module_context.rb"]
15
- s.homepage = "https://github.com/intridea/hashie"
16
- s.licenses = ["MIT"]
17
- s.rubygems_version = "2.4.5"
18
- s.summary = "Your friendly neighborhood hash library."
19
- s.test_files = ["spec/hashie/clash_spec.rb", "spec/hashie/dash_spec.rb", "spec/hashie/extensions/autoload_spec.rb", "spec/hashie/extensions/coercion_spec.rb", "spec/hashie/extensions/dash/indifferent_access_spec.rb", "spec/hashie/extensions/deep_fetch_spec.rb", "spec/hashie/extensions/deep_find_spec.rb", "spec/hashie/extensions/deep_locate_spec.rb", "spec/hashie/extensions/deep_merge_spec.rb", "spec/hashie/extensions/ignore_undeclared_spec.rb", "spec/hashie/extensions/indifferent_access_spec.rb", "spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb", "spec/hashie/extensions/key_conversion_spec.rb", "spec/hashie/extensions/mash/safe_assignment_spec.rb", "spec/hashie/extensions/merge_initializer_spec.rb", "spec/hashie/extensions/method_access_spec.rb", "spec/hashie/extensions/stringify_keys_spec.rb", "spec/hashie/extensions/symbolize_keys_spec.rb", "spec/hashie/hash_spec.rb", "spec/hashie/mash_spec.rb", "spec/hashie/parsers/yaml_erb_parser_spec.rb", "spec/hashie/rash_spec.rb", "spec/hashie/trash_spec.rb", "spec/hashie/version_spec.rb", "spec/spec_helper.rb", "spec/support/module_context.rb"]
20
-
21
- if s.respond_to? :specification_version then
22
- s.specification_version = 4
23
-
24
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
- s.add_development_dependency(%q<rake>, [">= 0"])
26
- s.add_development_dependency(%q<rspec>, ["~> 3.0"])
27
- else
28
- s.add_dependency(%q<rake>, [">= 0"])
29
- s.add_dependency(%q<rspec>, ["~> 3.0"])
30
- end
31
- else
32
- s.add_dependency(%q<rake>, [">= 0"])
33
- s.add_dependency(%q<rspec>, ["~> 3.0"])
34
- end
35
- end