object_json_mapper 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/object_json_mapper/base.rb +10 -7
- data/lib/object_json_mapper/serialization.rb +1 -1
- data/lib/object_json_mapper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 393df3aa965f8bd4c22243178f3e6494ffbe8344
|
4
|
+
data.tar.gz: 690b05e22cdc4e7e0d2def50afb9d6dc6fc78c31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90ebc057a00bdc161899345a49a75b28a0f384388e2ce726c893e2580e5b1053114bd7abf9165a3d894c39655892bc3759be06aa5c2464185e205fed7f5ad127
|
7
|
+
data.tar.gz: 5f7946bb77738e6314ec3032ae1e3858dce1ad933abe7658e4780d9b198bb8eb26d175f7ecacee93d8feb9d2c2347a2ae348ce23fccc3dad8b2f5fac32ffcf11
|
@@ -37,15 +37,18 @@ module ObjectJSONMapper
|
|
37
37
|
to_key.any?
|
38
38
|
end
|
39
39
|
|
40
|
+
def method_missing(method_name, *args, &block)
|
41
|
+
return attributes.fetch(method_name) if respond_to_missing?(method_name)
|
42
|
+
super
|
43
|
+
end
|
44
|
+
|
45
|
+
def respond_to_missing?(method_name, *)
|
46
|
+
attributes.key?(method_name)
|
47
|
+
end
|
48
|
+
|
40
49
|
# @param value [Hash]
|
41
50
|
def attributes=(value)
|
42
51
|
@attributes = HashWithIndifferentAccess.new(value)
|
43
|
-
|
44
|
-
@attributes.each do |method_name, _|
|
45
|
-
define_singleton_method(method_name) do
|
46
|
-
@attributes[method_name]
|
47
|
-
end
|
48
|
-
end
|
49
52
|
end
|
50
53
|
|
51
54
|
def ==(other)
|
@@ -90,7 +93,7 @@ module ObjectJSONMapper
|
|
90
93
|
def attribute(name, type: nil, default: nil)
|
91
94
|
define_method(name) do
|
92
95
|
return default.call if attributes.exclude?(name) && default
|
93
|
-
return type.call(
|
96
|
+
return type.call(self) if type
|
94
97
|
|
95
98
|
attributes[name]
|
96
99
|
end
|