pandarus 0.2.0 → 0.2.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.
@@ -1,5 +1,7 @@
1
1
  require 'active_support'
2
-
2
+ require 'active_support/inflector'
3
+ require 'date'
4
+
3
5
  module Pandarus
4
6
  class ModelBase
5
7
  def initialize(attributes = {})
@@ -12,15 +14,15 @@ module Pandarus
12
14
  end
13
15
  end
14
16
  end
15
-
17
+
16
18
  def attr(name)
17
19
  self.class.attribute_map[name.to_sym]
18
20
  end
19
-
21
+
20
22
  def has_attr?(name)
21
23
  self.class.attribute_map.has_key? name.to_sym
22
24
  end
23
-
25
+
24
26
  def inspect
25
27
  Hash[
26
28
  self.class.attribute_map.keys.map do |key|
@@ -28,19 +30,24 @@ module Pandarus
28
30
  end
29
31
  ].inspect.sub(/^\{/,"<#{self.class} ").sub(/\}$/,'>')
30
32
  end
31
-
33
+
32
34
  def assign(attr_name, value)
33
35
  props = attr(attr_name)
34
36
  if props[:type]
35
37
  if props[:container]
36
38
  value = value.map{ |v| props[:type].constantize.new(v) }
37
- else
38
- value = props[:type].constantize.new(v)
39
+ elsif !value.nil?
40
+ klass = props[:type].constantize # e.g. "Date"
41
+ if klass.respond_to?(:parse)
42
+ value = klass.parse(value)
43
+ else
44
+ value = klass.new(value)
45
+ end
39
46
  end
40
47
  end
41
48
  instance_variable_set("@#{attr_name}", value)
42
49
  end
43
-
50
+
44
51
  def to_body
45
52
  body = {}
46
53
  self.class.attribute_map.each_pair do |key, props|
@@ -1,3 +1,3 @@
1
1
  module Pandarus
2
- VERSION = '0.2.0' unless defined?(Pandarus::VERSION)
2
+ VERSION = '0.2.1' unless defined?(Pandarus::VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pandarus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: