lib/finix/resources/resource.rb in finix-0.7 vs lib/finix/resources/resource.rb in finix-0.8

- old
+ new

@@ -36,14 +36,13 @@ def save(options = {}, href = nil) options = options.is_a?(Finix::Resource) ? options.attributes : options @attributes = @attributes.merge options href ||= @hyperlinks[:self] - # href = @attributes.delete('href') method = :post if href.nil? - href = Finix.hypermedia_registry.key(self.class) + href = Finix.get_href self.class elsif not @attributes[:id].nil? method = :put end attributes_to_submit = self.sanitize @@ -57,13 +56,11 @@ end def sanitize to_submit = {} @attributes.each do |key, value| - if not value.is_a? Finix::Resource - to_submit[key] = value - end + to_submit[key] = value unless value.is_a? Finix::Resource end to_submit end def response @@ -76,28 +73,30 @@ if the_response return if the_response.body.to_s.length.zero? fresh = self.class.construct_from_response the_response.body else fresh = self.find(@hyperlinks[:self]) - # fresh = self.find(@attributes[:href]) end fresh and copy_from fresh self end - # alias refresh load! - def copy_from(other) other.instance_variables.each do |ivar| instance_variable_set ivar, other.instance_variable_get(ivar) end end def to_s "#{self.class.name.split('::').last || ''} #{@attributes}" end + def inspect + insp = super.inspect + "#{insp.split('::').last || ''}" + end + def self.included(base) base.extend ClassMethods end module ClassMethods @@ -130,9 +129,10 @@ response = Finix.get href construct_from_response response.body end alias find fetch + alias retrieve fetch end end end