module DataMapper::Model::Relationship
Public Instance Methods
blob(name)
click to toggle source
# File lib/appengine-utils/model/relationship.rb, line 4 def blob(name) add_relation_property(name) add_model_reader(name) add_model_writer(name) add_before_save_method(name) add_before_destroy_method(name) add_filter_methods(name) end
Private Instance Methods
add_before_destroy_method(name)
click to toggle source
# File lib/appengine-utils/model/relationship.rb, line 72 def add_before_destroy_method(name) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def before_destroy_#{name} if self.#{name}_id blob = AppEngineUtils::Datastore::Blob.new blob.delete(self.#{name}_id) end end RUBY end
add_before_save_method(name)
click to toggle source
# File lib/appengine-utils/model/relationship.rb, line 56 def add_before_save_method(name) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def before_save_#{name} if self.#{name}_id blob = AppEngineUtils::Datastore::Blob.new blob.delete(self.#{name}_id) end if #{name} blob = AppEngineUtils::Datastore::Blob.new key = blob.create(#{name}) self.#{name}_id= key end end RUBY end
add_filter_methods(name)
click to toggle source
# File lib/appengine-utils/model/relationship.rb, line 49 def add_filter_methods(name) class_eval <<-RUBY, __FILE__, __LINE__ + 1 before :save, :before_save_#{name} before :destroy, :before_destroy_#{name} RUBY end
add_model_reader(name)
click to toggle source
# File lib/appengine-utils/model/relationship.rb, line 18 def add_model_reader(name) class_eval <<-RUBY, __FILE__, __LINE__ + 1 chainable do def #{name} if self.#{name}_id && !@#{name} @#{name} = AppEngineUtils::Datastore::Blob.new.read(self.#{name}_id) end @#{name} end end RUBY end
add_model_writer(name)
click to toggle source
TODO: add model_writer
# File lib/appengine-utils/model/relationship.rb, line 33 def add_model_writer(name) class_eval <<-RUBY, __FILE__, __LINE__ + 1 chainable do def #{name}=(value) @#{name}=value end end RUBY end
add_relation_property(name)
click to toggle source
# File lib/appengine-utils/model/relationship.rb, line 43 def add_relation_property(name) class_eval <<-RUBY, __FILE__, __LINE__ + 1 property :#{name}_id, String RUBY end