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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e41159a2e0f3156c53e8c66f6b769ba59c4740e3
4
- data.tar.gz: eb171a61ccfdbb299de59d2856eb0e8607226db2
2
+ SHA256:
3
+ metadata.gz: aa8bb14cb875b48772a2c118ef62a6e604d863997354648c08aeb9cbcbb99689
4
+ data.tar.gz: c9b83eb8f3d753c5be3a1a093655ce55c34903df2b541641960e9c1ad8485bfc
5
5
  SHA512:
6
- metadata.gz: dc9222cf1cd7d977883d98b3b4613a571468d3820aaecec553771cd903fbdd59ab68b582f512d00229d29caa51a8583502696ee73112b94691e0ee419ae4ca88
7
- data.tar.gz: 530dbd4dcefa3610347bbaaee131d1e62d88802512477647af55e8116115e0ffb216a0708357f3cf4dcb99f87435f40a81ff4d1e238c566c0d673c4d7ebc06c3
6
+ metadata.gz: 64f929f0fff4ae36c5761da32142278f22f757bc708065e854f0b77ed4372199b59c752802694bd4281bf2094d0bb39355ea641ce3c831a201b8e8822b98b96e
7
+ data.tar.gz: a03ed8b68b439d53f15f7c96b1243a2a3957be709bd3b633a81c0cb6d060b3f6cbcf374bb417aafa5b38917f5483e253c98d175e5dea12c04028ed5633aa1029
data/.rubocop.yml CHANGED
@@ -1,25 +1,46 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.0
2
+ TargetRubyVersion: 2.7
3
3
  Include:
4
4
  - 'lib/**/*'
5
5
  - 'spec/**/*'
6
6
 
7
- Metrics/LineLength:
7
+ Layout/LineLength:
8
8
  Max: 120
9
9
 
10
- Style/Style/BlockDelimiters:
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/SpaceBeforeBlockBraces:
20
- EnforcedStyle: space
21
-
22
- Style/SpaceInsideParens:
43
+ Style/MissingRespondToMissing:
23
44
  Enabled: false
24
45
 
25
46
  Style/StringLiterals:
data/.travis.yml CHANGED
@@ -1,4 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
4
- before_install: gem install bundler -v 1.10.3
3
+ - 2.6.5
4
+ - 2.7.0
5
+ - 3.0.0
6
+ before_install: gem install bundler
7
+ script:
8
+ - bundle exec rspec
9
+ - bundle exec rubocop
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 #=> {:name=>'Anna', :job=>{:title=>'Engineer', :department=>'DevOps'}}
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
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "hash_dot"
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", "~> 1.10"
31
- spec.add_development_dependency "rake", "~> 10.0"
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", "~> 0.51"
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.keys.each { |key| dotify_hash(hash[key], use_default: use_default) if hash[key].is_a?(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
@@ -1,6 +1,8 @@
1
- require "hash_dot/version"
2
- require "symbol"
3
- require "hash"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "hash_dot/version"
4
+ require_relative "symbol"
5
+ require_relative "hash"
4
6
 
5
7
  module HashDot
6
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HashDot
2
- VERSION = "2.2.0".freeze
4
+ VERSION = "2.5.0"
3
5
  end
data/lib/symbol.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Symbol
2
4
  def chop
3
5
  to_s.chop.to_sym
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.2.0
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: 2017-11-20 00:00:00.000000000 Z
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: '1.10'
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: '1.10'
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: '10.0'
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: '10.0'
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: '0'
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: '0'
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.51'
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.51'
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
- rubyforge_project:
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.