lib/xeroizer/record/base.rb in xeroizer-float-2.15.3.13 vs lib/xeroizer/record/base.rb in xeroizer-float-2.15.3.14
- old
+ new
@@ -49,15 +49,17 @@
def [](attribute)
self.send(attribute)
end
def []=(attribute, value)
+ parent.mark_dirty(self) if parent
self.send("#{attribute}=".to_sym, value)
end
def attributes=(new_attributes)
return unless new_attributes.is_a?(Hash)
+ parent.mark_dirty(self) if parent
new_attributes.each do | key, value |
self.send("#{key}=".to_sym, value)
end
end
@@ -82,24 +84,46 @@
# Downloads the complete record if we only have a summary of the record.
def download_complete_record!
record = self.parent.find(self.id)
@attributes = record.attributes if record
@complete_record_downloaded = true
+ parent.mark_clean(self)
self
end
def save
return false unless valid?
if new_record?
create
else
update
end
+ saved!
+ end
+
+ def saved!
@complete_record_downloaded = true
+ parent.mark_clean(self)
true
end
+
+ def to_json(*args)
+ to_h.to_json(*args)
+ end
+ # Deprecated
+ def as_json(options = {})
+ to_h.to_json
+ end
+
+ def to_h
+ attrs = self.attributes.reject {|k, v| k == :parent }.map do |k, v|
+ [k, v.kind_of?(Array) ? v.map(&:to_h) : (v.respond_to?(:to_h) ? v.to_h : v)]
+ end
+ Hash[attrs]
+ end
+
def inspect
attribute_string = self.attributes.collect do |attr, value|
"#{attr.inspect}: #{value.inspect}"
end.join(", ")
"#<#{self.class} #{attribute_string}>"
@@ -110,10 +134,10 @@
# Attempt to create a new record.
def create
request = to_xml
log "[CREATE SENT] (#{__FILE__}:#{__LINE__}) #{request}"
- response = parent.http_put(request)
+ response = parent.http_post(request)
log "[CREATE RECEIVED] (#{__FILE__}:#{__LINE__}) #{response}"
parse_save_response(response)
end