Module: Bushido::Models
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/bushido/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/bushido/models.rb', line 3 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#bushido_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/bushido/models.rb', line 7 def bushido_save # It's possible we're saving an item just handed to us by Bushido, so we # don't want to re-publish it. We can detect it using the version. puts "what" # bushido_id.nil? This is new, it's from us (otherwise bushido would have given it an id), we should publish it. # bushido_version == self.find(self.id).bushido_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 Bushido databus" data = self.to_bushido begin response = Bushido::Data.publish(self.class.class_variable_get("@@bushi_model"), data) rescue => e puts e.inspect # TODO: Catch specific exceptions and bubble up errors (e.g. 'bushido 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 Bushido databus" end return true end |