lib/active_remote/persistence.rb in active_remote-1.8.0.rc1 vs lib/active_remote/persistence.rb in active_remote-1.8.0
- old
+ new
@@ -49,10 +49,20 @@
remote = self.new(attributes)
remote.save!
remote
end
+ # Instantiate a record with the given remote attributes. Generally used
+ # when retrieving records that already exist, so @new_record is set to false.
+ #
+ def instantiate(attributes, options = {})
+ new_object = self.new.instantiate(attributes)
+ new_object.readonly! if options[:readonly]
+
+ new_object
+ end
+
# Mark the class as readonly. Overrides instance-level readonly, making
# any instance of this class readonly.
def readonly!
@readonly = true
end
@@ -142,9 +152,15 @@
# Returns true if the remote record has been saved; otherwise, returns false.
#
def persisted?
return ! new_record?
+ end
+
+ # Sets the instance to be a readonly object
+ #
+ def readonly!
+ @readonly = true
end
# Returns true if the remote class or remote record is readonly; otherwise, returns false.
def readonly?
self.class.readonly? || @readonly