attribrutal 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/attribrutal/model.rb +16 -4
- data/lib/attribrutal/version.rb +1 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/lib/attribrutal/model.rb
CHANGED
@@ -7,29 +7,37 @@ module Attribrutal
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def initialize( attrs = {} )
|
10
|
-
|
10
|
+
all_attributes = attrs.symbolize_keys
|
11
|
+
attribrutal_attributes = all_attributes.select {|k,v| attribute_keys.include? k }
|
12
|
+
other_attributes = all_attributes.reject {|k,v| attribute_keys.include? k }
|
13
|
+
@attributes = attribrutal_attributes
|
14
|
+
other_attributes.map {|key, val| self.send("#{key}=", val) if respond_to?("#{key}=") }
|
11
15
|
end
|
12
16
|
|
13
17
|
def raw_attributes
|
14
|
-
|
18
|
+
attribute_keys.inject(Hash.new) do |attributes, attribute|
|
15
19
|
attributes[attribute] = @attributes[attribute]
|
16
20
|
attributes
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
24
|
def attributes
|
21
|
-
|
25
|
+
attribute_keys.inject(Hash.new) do |attributes, attribute|
|
22
26
|
attributes[attribute] = self.send(attribute)
|
23
27
|
attributes
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
31
|
+
def attribute_keys
|
32
|
+
self.class.attribute_keys
|
33
|
+
end
|
34
|
+
|
27
35
|
module ClassMethods
|
28
36
|
|
29
37
|
def attribute (sym, coercer=nil, attrs = {})
|
30
38
|
|
31
39
|
define_method(sym) do
|
32
|
-
if coercer
|
40
|
+
if coercer && coercer.respond_to?(:coerce)
|
33
41
|
coercer.send(:coerce, @attributes[sym], attrs[:default])
|
34
42
|
else
|
35
43
|
@attributes[sym] || default
|
@@ -51,6 +59,10 @@ module Attribrutal
|
|
51
59
|
@attributes
|
52
60
|
end
|
53
61
|
|
62
|
+
def attribute_keys
|
63
|
+
@attributes.keys
|
64
|
+
end
|
65
|
+
|
54
66
|
end
|
55
67
|
|
56
68
|
end
|
data/lib/attribrutal/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribrutal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -96,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
segments:
|
98
98
|
- 0
|
99
|
-
hash:
|
99
|
+
hash: 2151528194976546338
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
none: false
|
102
102
|
requirements:
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
segments:
|
107
107
|
- 0
|
108
|
-
hash:
|
108
|
+
hash: 2151528194976546338
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
111
|
rubygems_version: 1.8.23
|