hash_dot 2.2.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +28 -7
- data/.travis.yml +7 -2
- data/README.md +4 -2
- data/bin/console +1 -0
- data/hash_dot.gemspec +4 -4
- data/lib/hash.rb +25 -3
- data/lib/hash_dot.rb +5 -3
- data/lib/hash_dot/version.rb +3 -1
- data/lib/symbol.rb +2 -0
- metadata +17 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa8bb14cb875b48772a2c118ef62a6e604d863997354648c08aeb9cbcbb99689
|
4
|
+
data.tar.gz: c9b83eb8f3d753c5be3a1a093655ce55c34903df2b541641960e9c1ad8485bfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64f929f0fff4ae36c5761da32142278f22f757bc708065e854f0b77ed4372199b59c752802694bd4281bf2094d0bb39355ea641ce3c831a201b8e8822b98b96e
|
7
|
+
data.tar.gz: a03ed8b68b439d53f15f7c96b1243a2a3957be709bd3b633a81c0cb6d060b3f6cbcf374bb417aafa5b38917f5483e253c98d175e5dea12c04028ed5633aa1029
|
data/.rubocop.yml
CHANGED
@@ -1,25 +1,46 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.7
|
3
3
|
Include:
|
4
4
|
- 'lib/**/*'
|
5
5
|
- 'spec/**/*'
|
6
6
|
|
7
|
-
|
7
|
+
Layout/LineLength:
|
8
8
|
Max: 120
|
9
9
|
|
10
|
-
|
10
|
+
Layout/SpaceBeforeBlockBraces:
|
11
|
+
EnforcedStyle: space
|
12
|
+
|
13
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Layout/SpaceInsideParens:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/BlockDelimiters:
|
11
26
|
Enabled: false
|
12
27
|
|
13
28
|
Style/Documentation:
|
14
29
|
Enabled: false
|
15
30
|
|
31
|
+
Style/ExpandPathArguments:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/Lambda:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/MethodMissingSuper:
|
38
|
+
Enabled: false
|
39
|
+
|
16
40
|
Style/MutableConstant:
|
17
41
|
Enabled: true
|
18
42
|
|
19
|
-
Style/
|
20
|
-
EnforcedStyle: space
|
21
|
-
|
22
|
-
Style/SpaceInsideParens:
|
43
|
+
Style/MissingRespondToMissing:
|
23
44
|
Enabled: false
|
24
45
|
|
25
46
|
Style/StringLiterals:
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,10 @@ HashDot allows you to get and set your Ruby hash properties with a dot syntax.
|
|
18
18
|
user.job.title #=> 'Engineer'
|
19
19
|
user.job.department = 'DevOps'
|
20
20
|
user.job.department #=> 'DevOps'
|
21
|
-
user
|
21
|
+
user.send('beverages=', {}.to_dot)
|
22
|
+
user.send('beverages.coffee=', 'Short Black')
|
23
|
+
user.send('beverages.coffee') #=> 'Short Black'
|
24
|
+
user #=> {:name=>'Anna', :job=>{:title=>'Engineer', :department=>'DevOps'}, :beverages=> { :coffee => 'Short Black'} }
|
22
25
|
```
|
23
26
|
|
24
27
|
You can also allow dot syntax for all hashes via the class setting.
|
@@ -115,4 +118,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/adstee
|
|
115
118
|
## License
|
116
119
|
|
117
120
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
118
|
-
|
data/bin/console
CHANGED
data/hash_dot.gemspec
CHANGED
@@ -27,10 +27,10 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_development_dependency "bundler"
|
31
|
-
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "bundler"
|
31
|
+
spec.add_development_dependency "rake"
|
32
32
|
spec.add_development_dependency "rspec"
|
33
|
-
spec.add_development_dependency "json"
|
33
|
+
spec.add_development_dependency "json", '>= 2.5.1'
|
34
34
|
spec.add_development_dependency "pry"
|
35
|
-
spec.add_development_dependency "rubocop"
|
35
|
+
spec.add_development_dependency "rubocop"
|
36
36
|
end
|
data/lib/hash.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Hash
|
2
4
|
class << self
|
3
5
|
attr_accessor :use_dot_syntax
|
@@ -16,6 +18,10 @@ class Hash
|
|
16
18
|
def method_missing(method, *args)
|
17
19
|
return super(method, *args) unless to_dot?
|
18
20
|
|
21
|
+
method, chain = method.to_s.split(".", 2).map(&:to_sym)
|
22
|
+
|
23
|
+
return send(method).send(chain, *args) if chain
|
24
|
+
|
19
25
|
prop = create_prop(method)
|
20
26
|
|
21
27
|
if setter?(method)
|
@@ -27,20 +33,36 @@ class Hash
|
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
|
-
def respond_to?(method, include_all=false)
|
36
|
+
def respond_to?(method, include_all = false)
|
31
37
|
return super(method, include_all) unless to_dot?
|
38
|
+
|
32
39
|
prop = create_prop(method)
|
33
40
|
return true if key?(prop)
|
41
|
+
|
34
42
|
super(method, include_all)
|
35
43
|
end
|
36
|
-
|
44
|
+
|
37
45
|
private
|
38
46
|
|
47
|
+
def dotify_obj(obj, use_default: false)
|
48
|
+
case obj
|
49
|
+
when Array
|
50
|
+
obj.each do |el|
|
51
|
+
dotify_obj(el, use_default: use_default)
|
52
|
+
end
|
53
|
+
when Hash
|
54
|
+
dotify_hash(obj, use_default: use_default)
|
55
|
+
# else no-op
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
39
59
|
def dotify_hash(hash, use_default: false)
|
40
60
|
hash.use_dot_syntax = true
|
41
61
|
hash.hash_dot_use_default = use_default
|
42
62
|
|
43
|
-
hash.
|
63
|
+
hash.each_value do |val|
|
64
|
+
dotify_obj(val, use_default: use_default)
|
65
|
+
end
|
44
66
|
end
|
45
67
|
|
46
68
|
def to_dot?
|
data/lib/hash_dot.rb
CHANGED
data/lib/hash_dot/version.rb
CHANGED
data/lib/symbol.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_dot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Steel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.5.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.5.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0
|
96
|
+
version: '0'
|
97
97
|
description: HashDot allows you to call hash properties with a dot the same way you
|
98
98
|
would call, say, ActiveRecord relationships and attributes. More traversable and
|
99
99
|
often faster than OpenStruct.
|
@@ -139,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
|
-
|
143
|
-
rubygems_version: 2.5.2
|
142
|
+
rubygems_version: 3.2.3
|
144
143
|
signing_key:
|
145
144
|
specification_version: 4
|
146
145
|
summary: Use dot syntax with Ruby hashes.
|