hash_ext 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hash_ext/accessible.rb +29 -12
- data/lib/hash_ext/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65fdcdef6f30c72fd67f580a85b229dc482436db
|
4
|
+
data.tar.gz: 134b5b4bb3473bb91a70086944083d59bd863496
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 922fc626a447c9d1a10630bec09f1276321e776b400e547ff867d054caf3662cb4799995fc6746a88047f3ed06570f72dbe00d846385741bbbe1b45923d09e4d
|
7
|
+
data.tar.gz: 15d7e5d4a95549accc7328a6a091b1411431e26b5a401aa7b086d6310bf41aefafb6e2992449ddb4a28ffc82c5219ebdfe16a542591e6e5e56d0780323d52e85
|
data/lib/hash_ext/accessible.rb
CHANGED
@@ -1,24 +1,41 @@
|
|
1
1
|
class Hash
|
2
2
|
class Accessible < Indifferent
|
3
3
|
|
4
|
+
def self.make_accessible(value)
|
5
|
+
if value.kind_of? Hash
|
6
|
+
self.new value
|
7
|
+
elsif value.kind_of? ::Array
|
8
|
+
Array.new value
|
9
|
+
else
|
10
|
+
value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Array < SimpleDelegator
|
15
|
+
|
16
|
+
def initialize(array)
|
17
|
+
super array.map { |v| Accessible.make_accessible v }
|
18
|
+
end
|
19
|
+
|
20
|
+
def push(value)
|
21
|
+
super Accessible.make_accessible(value)
|
22
|
+
end
|
23
|
+
alias_method :<<, :push
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def []=(key, value)
|
28
|
+
super key, self.class.make_accessible(value)
|
29
|
+
end
|
30
|
+
|
4
31
|
private
|
5
32
|
|
6
33
|
def method_missing(method, *args, &block)
|
7
34
|
if method.to_s.end_with? '='
|
8
35
|
key = method[0..-2]
|
9
|
-
self[key] =
|
10
|
-
else
|
11
|
-
make_accessible self[method]
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def make_accessible(value)
|
16
|
-
if value.kind_of? Hash
|
17
|
-
self.class.new value
|
18
|
-
elsif value.kind_of? Array
|
19
|
-
value.map { |v| make_accessible v }
|
36
|
+
self[key] = args[0]
|
20
37
|
else
|
21
|
-
|
38
|
+
self[method]
|
22
39
|
end
|
23
40
|
end
|
24
41
|
|
data/lib/hash_ext/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|