Module: Cloudfuji::Models
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/cloudfuji/models.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
3 4 5 |
# File 'lib/cloudfuji/models.rb', line 3 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#cloudfuji_save ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cloudfuji/models.rb', line 7 def cloudfuji_save # It's possible we're saving an item just handed to us by Cloudfuji, so we # don't want to re-publish it. We can detect it using the version. puts "what" # cloudfuji_id.nil? This is new, it's from us (otherwise cloudfuji would have given it an id), we should publish it. # cloudfuji_version == self.find(self.id).cloudfuji_version The version hasn't changed, our data has, we should publish it puts "new_record? #{self.new_record?}" puts "self.id = #{self.id}" puts "ido_id.nil? #{ido_id.nil?}" puts "ido_version == self.class.find(self.id).ido_version ? #{ido_version == self.class.find(self.id).ido_version}" unless self.new_record? if self.ido_id.nil? or (not self.new_record? and self.ido_version == self.class.find(self.id).ido_version) puts "Local change, publishing to Cloudfuji databus" data = self.to_cloudfuji begin response = Cloudfuji::Data.publish(self.class.class_variable_get("@@ido_model"), data) rescue => e puts e.inspect # TODO: Catch specific exceptions and bubble up errors (e.g. 'cloudfuji is down', 'model is malformed', etc.) return false end self.ido_version = response["ido_version"] self.ido_id ||= response["ido_id"] puts response.inspect else puts "Remote change, not publishing to Cloudfuji databus" end return true end |