object_json_mapper 0.1.0 → 0.1.1

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: acb7c25978fc740c3c44e2eee2e7e167c4ff4594
4
- data.tar.gz: 97b39de00d7d216d18f0756a554a4a919a3540cf
3
+ metadata.gz: 393df3aa965f8bd4c22243178f3e6494ffbe8344
4
+ data.tar.gz: 690b05e22cdc4e7e0d2def50afb9d6dc6fc78c31
5
5
  SHA512:
6
- metadata.gz: 075cdd680bd8fe0bd87e2d120aa584d39a1c535b0f5578a939a12051133fbca161f16e7610fe3c312895f03129b338cbd861c2d812efba707d8b7c2aab56fc9e
7
- data.tar.gz: 1a2836e62511aad8d0d10e1e7f019f5295eadada373d8cb5af5ba5b61a89366e2e00497836fad71ffb98e1ac946c009a809b7dbc837bc75665ccbdbb4776406d
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(attributes[name]) if type
96
+ return type.call(self) if type
94
97
 
95
98
  attributes[name]
96
99
  end
@@ -1,6 +1,6 @@
1
1
  module ObjectJSONMapper
2
2
  module Serialization
3
- def serializable_hash
3
+ def serializable_hash(_)
4
4
  attributes
5
5
  end
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module ObjectJSONMapper
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object_json_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - droptheplot