serializer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/serializer.rb CHANGED
@@ -28,18 +28,23 @@ module Serializer
28
28
  initializer.each do |method, options|
29
29
 
30
30
  define_method "#{method}" do
31
- result = send(name)[method.intern]
32
- return options[:default] if result.nil?
31
+ hash = send(name)
32
+ result = hash[method.intern] if hash
33
+ return options[:default] if hash.nil? or result.nil?
33
34
  return result
34
35
  end
35
36
 
36
37
  define_method "#{method}?" do
37
- result = send(name)[method.intern]
38
- return options[:default] if result.nil?
38
+ hash = send(name)
39
+ result = hash[method.intern]
40
+ return options[:default] if hash.nil? or result.nil?
39
41
  return result
40
42
  end
41
43
 
42
44
  define_method "#{method}=" do |value|
45
+ send("#{name}=", {}) unless send(name)
46
+ hash = send(name)
47
+
43
48
  if options[:type] and value
44
49
  case options[:type].intern
45
50
  when :float then value = value.to_f if value.respond_to? :to_f
@@ -1,3 +1,3 @@
1
1
  module Serializer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: