hashie 3.5.3 → 3.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +28 -1
- data/lib/hashie.rb +1 -0
- data/lib/hashie/extensions/mash/symbolize_keys.rb +38 -0
- data/lib/hashie/mash.rb +1 -1
- data/lib/hashie/railtie.rb +10 -6
- data/lib/hashie/version.rb +1 -1
- data/spec/hashie/extensions/mash/symbolize_keys_spec.rb +39 -0
- data/spec/integration/rails-without-dependency/integration_spec.rb +15 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b244f4fdc55d9650174134efecbb99d32e75ef14
|
4
|
+
data.tar.gz: 5a00da5d9da33a9a7bdc3f821d16e83dfca65ced
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f948ef11d034b29d9b6a6d9473be7528ba2e3b2e79e9a164fd622194ed39ab29a7b6d37ea1a4f4eeb0232a28fb3ff8d6b19cba3b059a13b33e5894180d76c7c7
|
7
|
+
data.tar.gz: e3ac5f5715323c230b2beedd38a4e47a9a2d199f17a4535072d75c645364ac14b2b4f95e4985de39db270b17f10b92989266eb5d4bb2c4a834a386a7807a04dd
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,19 @@ scheme are considered to be bugs.
|
|
6
6
|
|
7
7
|
[semver]: http://semver.org/spec/v2.0.0.html
|
8
8
|
|
9
|
+
## [3.5.4] - 2017-02-22
|
10
|
+
|
11
|
+
[3.5.4]: https://github.com/intridea/hashie/compare/v3.5.3...v3.5.4
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
* [#412](https://github.com/intridea/hashie/pull/412): Added a Hashie::Extensions::Mash::SymbolizeKeys extension that overrides the default stringification behavior for keys - [@michaelherold](https://github.com/michaelherold).
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
* [#409](https://github.com/intridea/hashie/pull/409): Fixed Railtie detection for projects where Rails is defined but Railties are not availble - [@CallumD](https://github.com/callumd).
|
20
|
+
* [#411](https://github.com/intridea/hashie/pull/411): Fixed a performance regression from 3.4.3 that caused a 10x slowdown in OmniAuth - [@michaelherold](https://github.com/michaelherold).
|
21
|
+
|
9
22
|
## [3.5.3] - 2017-02-11
|
10
23
|
|
11
24
|
[3.5.3]: https://github.com/intridea/hashie/compare/v3.5.2...v3.5.3
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ $ gem install hashie
|
|
20
20
|
|
21
21
|
## Upgrading
|
22
22
|
|
23
|
-
You're reading the documentation for the stable release of Hashie, 3.5.
|
23
|
+
You're reading the documentation for the stable release of Hashie, 3.5.4. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
|
24
24
|
|
25
25
|
## Hash Extensions
|
26
26
|
|
@@ -561,6 +561,33 @@ safe_mash.zip = 'Test' # => ArgumentError
|
|
561
561
|
safe_mash[:zip] = 'test' # => still ArgumentError
|
562
562
|
```
|
563
563
|
|
564
|
+
### Mash Extension:: SymbolizeKeys
|
565
|
+
|
566
|
+
This extension can be mixed into a Mash to change the default behavior of converting keys to strings. After mixing this extension into a Mash, the Mash will convert all keys to symbols.
|
567
|
+
|
568
|
+
```ruby
|
569
|
+
class SymbolizedMash < ::Hashie::Mash
|
570
|
+
include Hashie::Extensions::Mash::SymbolizeKeys
|
571
|
+
end
|
572
|
+
|
573
|
+
symbol_mash = SymbolizedMash.new
|
574
|
+
symbol_mash['test'] = 'value'
|
575
|
+
symbol_mash.test #=> 'value'
|
576
|
+
symbol_mash.to_h #=> {test: 'value'}
|
577
|
+
```
|
578
|
+
|
579
|
+
There is a major benefit and coupled with a major trade-off to this decision (at least on older Rubies). As a benefit, by using symbols as keys, you will be able to use the implicit conversion of a Mash via the `#to_hash` method to destructure (or splat) the contents of a Mash out to a block. This can be handy for doing iterations through the Mash's keys and values, as follows:
|
580
|
+
|
581
|
+
```ruby
|
582
|
+
symbol_mash = SymbolizedMash.new(id: 123, name: 'Rey')
|
583
|
+
symbol_mash.each do |key, value|
|
584
|
+
# key is :id, then :name
|
585
|
+
# value is 123, then 'Rey'
|
586
|
+
end
|
587
|
+
```
|
588
|
+
|
589
|
+
However, on Rubies less than 2.0, this means that every key you send to the Mash will generate a symbol. Since symbols are not garbage-collected on older versions of Ruby, this can cause a slow memory leak when using a symbolized Mash with data generated from user input.
|
590
|
+
|
564
591
|
## Dash
|
565
592
|
|
566
593
|
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.
|
data/lib/hashie.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Hashie
|
2
|
+
module Extensions
|
3
|
+
module Mash
|
4
|
+
# Overrides Mash's default behavior of converting keys to strings
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# class LazyResponse < Hashie::Mash
|
8
|
+
# include Hashie::Extensions::Mash::SymbolizedKeys
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# response = LazyResponse.new("id" => 123, "name" => "Rey").to_h
|
12
|
+
# #=> {id: 123, name: "Rey"}
|
13
|
+
#
|
14
|
+
# @api public
|
15
|
+
module SymbolizeKeys
|
16
|
+
# Hook for being included in a class
|
17
|
+
#
|
18
|
+
# @api private
|
19
|
+
# @return [void]
|
20
|
+
# @raise [ArgumentError] when the base class isn't a Mash
|
21
|
+
def self.included(base)
|
22
|
+
fail ArgumentError, "#{base} must descent from Hashie::Mash" unless base <= Hashie::Mash
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Converts a key to a symbol
|
28
|
+
#
|
29
|
+
# @api private
|
30
|
+
# @param [String, Symbol] key the key to convert to a symbol
|
31
|
+
# @return [void]
|
32
|
+
def convert_key(key)
|
33
|
+
key.to_sym
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/hashie/mash.rb
CHANGED
@@ -145,7 +145,7 @@ module Hashie
|
|
145
145
|
def custom_writer(key, value, convert = true) #:nodoc:
|
146
146
|
key_as_symbol = (key = convert_key(key)).to_sym
|
147
147
|
|
148
|
-
log_built_in_message(key_as_symbol) if
|
148
|
+
log_built_in_message(key_as_symbol) if respond_to?(key_as_symbol)
|
149
149
|
regular_writer(key, convert ? convert_value(value) : value)
|
150
150
|
end
|
151
151
|
|
data/lib/hashie/railtie.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'rails/railtie'
|
2
3
|
|
3
|
-
module Hashie
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Hashie
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
# Set the Hashie.logger to use Rails.logger when used with rails.
|
7
|
+
initializer 'hashie.configure_logger', after: 'initialize_logger' do
|
8
|
+
Hashie.logger = Rails.logger
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
12
|
+
rescue LoadError => e
|
13
|
+
Hashie.logger.info("Hashie skipping railtie as #{e.message}")
|
10
14
|
end
|
data/lib/hashie/version.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Hashie::Extensions::Mash::SymbolizeKeys do
|
4
|
+
it 'raises an error when included in a class that is not a Mash' do
|
5
|
+
expect do
|
6
|
+
Class.new do
|
7
|
+
include Hashie::Extensions::Mash::SymbolizeKeys
|
8
|
+
end
|
9
|
+
end.to raise_error(ArgumentError)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'symbolizes all keys in the Mash' do
|
13
|
+
my_mash = Class.new(Hashie::Mash) do
|
14
|
+
include Hashie::Extensions::Mash::SymbolizeKeys
|
15
|
+
end
|
16
|
+
|
17
|
+
expect(my_mash.new('test' => 'value').to_h).to eq(test: 'value')
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'implicit to_hash on double splat' do
|
21
|
+
let(:destructure) { ->(**opts) { opts } }
|
22
|
+
let(:my_mash) do
|
23
|
+
Class.new(Hashie::Mash) do
|
24
|
+
include Hashie::Extensions::Mash::SymbolizeKeys
|
25
|
+
end
|
26
|
+
end
|
27
|
+
let(:instance) { my_mash.new('outer' => { 'inner' => 42 }, 'testing' => [1, 2, 3]) }
|
28
|
+
|
29
|
+
subject { destructure.call(instance) }
|
30
|
+
|
31
|
+
it 'is converted on method calls' do
|
32
|
+
expect(subject).to eq(outer: { inner: 42 }, testing: [1, 2, 3])
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'is converted on explicit operator call' do
|
36
|
+
expect(**instance).to eq(outer: { inner: 42 }, testing: [1, 2, 3])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
|
3
|
+
RSpec.describe 'partial-rails' do
|
4
|
+
context 'when Rails constant is present but the railties are not' do
|
5
|
+
before(:all) do
|
6
|
+
class Rails
|
7
|
+
# A class about railways
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'does not raise an exception when we require hashie' do
|
12
|
+
expect { require 'hashie' }.not_to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.
|
4
|
+
version: 3.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-02-
|
12
|
+
date: 2017-02-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/hashie/extensions/indifferent_access.rb
|
87
87
|
- lib/hashie/extensions/key_conversion.rb
|
88
88
|
- lib/hashie/extensions/mash/safe_assignment.rb
|
89
|
+
- lib/hashie/extensions/mash/symbolize_keys.rb
|
89
90
|
- lib/hashie/extensions/merge_initializer.rb
|
90
91
|
- lib/hashie/extensions/method_access.rb
|
91
92
|
- lib/hashie/extensions/parsers/yaml_erb_parser.rb
|
@@ -119,6 +120,7 @@ files:
|
|
119
120
|
- spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb
|
120
121
|
- spec/hashie/extensions/key_conversion_spec.rb
|
121
122
|
- spec/hashie/extensions/mash/safe_assignment_spec.rb
|
123
|
+
- spec/hashie/extensions/mash/symbolize_keys_spec.rb
|
122
124
|
- spec/hashie/extensions/merge_initializer_spec.rb
|
123
125
|
- spec/hashie/extensions/method_access_spec.rb
|
124
126
|
- spec/hashie/extensions/strict_key_access_spec.rb
|
@@ -137,6 +139,7 @@ files:
|
|
137
139
|
- spec/integration/omniauth-oauth2/some_site.rb
|
138
140
|
- spec/integration/omniauth/app.rb
|
139
141
|
- spec/integration/omniauth/integration_spec.rb
|
142
|
+
- spec/integration/rails-without-dependency/integration_spec.rb
|
140
143
|
- spec/integration/rails/app.rb
|
141
144
|
- spec/integration/rails/integration_spec.rb
|
142
145
|
- spec/spec_helper.rb
|
@@ -164,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
167
|
version: '0'
|
165
168
|
requirements: []
|
166
169
|
rubyforge_project:
|
167
|
-
rubygems_version: 2.6.
|
170
|
+
rubygems_version: 2.6.10
|
168
171
|
signing_key:
|
169
172
|
specification_version: 4
|
170
173
|
summary: Your friendly neighborhood hash library.
|
@@ -185,6 +188,7 @@ test_files:
|
|
185
188
|
- spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb
|
186
189
|
- spec/hashie/extensions/key_conversion_spec.rb
|
187
190
|
- spec/hashie/extensions/mash/safe_assignment_spec.rb
|
191
|
+
- spec/hashie/extensions/mash/symbolize_keys_spec.rb
|
188
192
|
- spec/hashie/extensions/merge_initializer_spec.rb
|
189
193
|
- spec/hashie/extensions/method_access_spec.rb
|
190
194
|
- spec/hashie/extensions/strict_key_access_spec.rb
|
@@ -205,6 +209,7 @@ test_files:
|
|
205
209
|
- spec/integration/omniauth-oauth2/some_site.rb
|
206
210
|
- spec/integration/rails/app.rb
|
207
211
|
- spec/integration/rails/integration_spec.rb
|
212
|
+
- spec/integration/rails-without-dependency/integration_spec.rb
|
208
213
|
- spec/spec_helper.rb
|
209
214
|
- spec/support/integration_specs.rb
|
210
215
|
- spec/support/logger.rb
|