vidibus-resource 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,9 +6,6 @@ module Vidibus::Resource
6
6
  module Mongoid
7
7
  extend ActiveSupport::Concern
8
8
 
9
- # Valid types in Mongoid
10
- VALID_TYPES = [Array, BigDecimal, Boolean, Date, DateTime, Float, Hash, Integer, String, Symbol, Time]
11
-
12
9
  included do
13
10
  include Vidibus::Uuid::Mongoid
14
11
 
@@ -60,16 +57,34 @@ module Vidibus::Resource
60
57
  def set_resource_attributes(force = false)
61
58
  if resource_attributes_changed? or force == true
62
59
  for key, value in resource_attributes
60
+ meth = key.to_s
61
+
62
+ unless respond_to?("#{meth}=")
63
+ self.class.class_eval <<-END
64
+ def #{meth}=(value)
65
+ self.write_attribute(:#{meth}, value)
66
+ end
67
+ END
68
+ end
63
69
 
64
- setter = respond_to?("#{key}=")
65
- unless setter or respond_to?(key) # Check for setter and getter!
66
- field_type = VALID_TYPES.include?(value.class) ? value.class : String
67
- self.class.class_eval do
68
- field key.to_sym, :type => field_type # Mongoid field
69
- end
70
- setter = true
70
+ unless respond_to?("#{meth}?")
71
+ self.class.class_eval <<-END
72
+ def #{meth}?
73
+ attr = read_attribute(:#{meth})
74
+ (attr === true) ? true : (attr === false) ? false : attr.present?
75
+ end
76
+ END
71
77
  end
72
- send("#{key}=", value) if setter
78
+
79
+ unless respond_to?(meth)
80
+ self.class.class_eval <<-END
81
+ def #{meth}
82
+ read_attribute(:#{meth})
83
+ end
84
+ END
85
+ end
86
+
87
+ send("#{meth}=", value)
73
88
  end
74
89
  end
75
90
  true # ensure true!
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Resource
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-resource
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Andr\xC3\xA9 Pankratz"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-18 00:00:00 +01:00
18
+ date: 2011-01-19 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency