4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/samurai/active_resource_support.rb', line 4
def self.included(base)
if [ActiveResource::VERSION::MAJOR, ActiveResource::VERSION::MINOR].compact.join('.').to_f < 3.0
base.const_set 'EMPTY_ATTRIBUTES', base.const_get('KNOWN_ATTRIBUTES').inject(HashWithIndifferentAccess.new) {|h, k| h[k] = ''; h}
base.class_eval do
def initialize(attrs={})
_empty_attributes = self.class.const_get('EMPTY_ATTRIBUTES')
super(_empty_attributes.merge(attrs))
end
def update_attributes(attributes)
load(attributes) && save
end
end
else
base.schema { string *base.const_get('KNOWN_ATTRIBUTES') }
end
end
|