hashd 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c05f197d0a32b1399321a407b9b7b4537d6577e5
4
- data.tar.gz: 0bb016c2a536ed413c919260c6c48a681b083498
3
+ metadata.gz: 6974e36189c3cc51df299521ae90bfac6dc0bb88
4
+ data.tar.gz: e2bc3b72188924c27629173fee58426f01de146e
5
5
  SHA512:
6
- metadata.gz: bbbb938551750eafef61ef7641028077c9ccfdb8b00f0b0fe61deda6a0e1b28b44160721e4f27f17f062a689b27f521871b13f4a1f937379026310f06ed95751
7
- data.tar.gz: 2e0d3a77097f005142488f95c55d4cf7ee6b4d81a4aa8d1ae57572c0bf509b6dd35dcca33c3a24093fceb4b02924e9a11dc828e0c6961e45d6df09a69419b697
6
+ metadata.gz: 488d0f0dedb0cbb8970456b60559bb86721ab274c7cdf0d03fcaa215e6d8344aa15c99bd850b0bd858701fa36e4b733a6b6b39ad005134a7c123fc23d9600024
7
+ data.tar.gz: 52c1caa0ea4197aa02b86700c0eff2f17021cee0c829908be02c5df9d0c08e5615697e529ac4ac0e92d16ef750a6d0dc2406283c021ab99d36e24a0bc077a50d
@@ -0,0 +1,3 @@
1
+ **Version 0.0.1** - *2017-07-14*
2
+
3
+ - Initial commit
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'hashd'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.date = '2017-07-14'
5
5
  s.summary = "Hash dot syntax"
6
6
  s.description = "Give any hash dot syntax. Supports nested properties, mutates original hash."
@@ -1,26 +1,31 @@
1
1
  class Hash
2
2
 
3
- attr_accessor :dot
3
+ attr_accessor :use_dot_syntax
4
4
 
5
5
  def to_dot
6
6
  dotify(self); self
7
7
  end
8
8
 
9
+ # Using method missing.
9
10
  def method_missing(name, *args, &block)
10
- return super(name, *args, &block) unless dot
11
+ return super(name, *args, &block) unless use_dot_syntax
11
12
 
13
+ # Check for value first or assign
12
14
  if name[-1] == '='
13
- self[name[0..-2].to_sym] = args[0]
14
- else
15
- self[name] || self[name.to_s]
15
+ return self[name[0..-2].to_sym] = args[0]
16
+ elsif (val = self[name] || self[name.to_s])
17
+ return val
16
18
  end
19
+
20
+ # Pass to methods if value not found
21
+ return super(name, *args, &block) if self.respond_to?(name)
17
22
  end
18
23
 
19
24
  private
20
25
 
21
26
  # Set up each hash for dot syntax
22
27
  def dotify(h)
23
- h.dot = true; h.keys.each{|key| dotify(h[key]) if h[key].is_a?(::Hash)}
28
+ h.use_dot_syntax = true; h.keys.each{|key| dotify(h[key]) if h[key].is_a?(::Hash)}
24
29
  end
25
30
 
26
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fugroup Limited
@@ -32,6 +32,7 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - ".gitignore"
35
+ - CHANGELOG.md
35
36
  - Gemfile
36
37
  - LICENSE
37
38
  - README.md