c280b3a29b
Refactored basic directory structure. Moved to ActiveSupport for Validations and Callbacks. Cleaned up older code, and removed support for text property types.
118 lines
2.7 KiB
Ruby
118 lines
2.7 KiB
Ruby
class WithDefaultValues < CouchRest::Model::Base
|
|
use_database TEST_SERVER.default_database
|
|
property :preset, Object, :default => {:right => 10, :top_align => false}
|
|
property :set_by_proc, Time, :default => Proc.new{Time.now}
|
|
property :tags, [String], :default => []
|
|
property :read_only_with_default, :default => 'generic', :read_only => true
|
|
property :default_false, TrueClass, :default => false
|
|
property :name
|
|
timestamps!
|
|
end
|
|
|
|
class WithSimplePropertyType < CouchRest::Model::Base
|
|
use_database TEST_SERVER.default_database
|
|
property :name, String
|
|
property :preset, String, :default => 'none'
|
|
property :tags, [String]
|
|
timestamps!
|
|
end
|
|
|
|
class WithCallBacks < CouchRest::Model::Base
|
|
use_database TEST_SERVER.default_database
|
|
property :name
|
|
property :run_before_validate
|
|
property :run_after_validate
|
|
property :run_before_save
|
|
property :run_after_save
|
|
property :run_before_create
|
|
property :run_after_create
|
|
property :run_before_update
|
|
property :run_after_update
|
|
|
|
before_validate do |object|
|
|
object.run_before_validate = true
|
|
end
|
|
after_validate do |object|
|
|
object.run_after_validate = true
|
|
end
|
|
before_save do |object|
|
|
object.run_before_save = true
|
|
end
|
|
after_save do |object|
|
|
object.run_after_save = true
|
|
end
|
|
before_create do |object|
|
|
object.run_before_create = true
|
|
end
|
|
after_create do |object|
|
|
object.run_after_create = true
|
|
end
|
|
before_update do |object|
|
|
object.run_before_update = true
|
|
end
|
|
after_update do |object|
|
|
object.run_after_update = true
|
|
end
|
|
|
|
property :run_one
|
|
property :run_two
|
|
property :run_three
|
|
|
|
before_save :run_one_method, :run_two_method do |object|
|
|
object.run_three = true
|
|
end
|
|
def run_one_method
|
|
self.run_one = true
|
|
end
|
|
def run_two_method
|
|
self.run_two = true
|
|
end
|
|
|
|
attr_accessor :run_it
|
|
property :conditional_one
|
|
property :conditional_two
|
|
|
|
before_save :conditional_one_method, :conditional_two_method, :if => proc { self.run_it }
|
|
def conditional_one_method
|
|
self.conditional_one = true
|
|
end
|
|
def conditional_two_method
|
|
self.conditional_two = true
|
|
end
|
|
end
|
|
|
|
class WithTemplateAndUniqueID < CouchRest::Model::Base
|
|
use_database TEST_SERVER.default_database
|
|
unique_id do |model|
|
|
model['important-field']
|
|
end
|
|
property :preset, :default => 'value'
|
|
property :has_no_default
|
|
end
|
|
|
|
class WithGetterAndSetterMethods < CouchRest::Model::Base
|
|
use_database TEST_SERVER.default_database
|
|
|
|
property :other_arg
|
|
def arg
|
|
other_arg
|
|
end
|
|
|
|
def arg=(value)
|
|
self.other_arg = "foo-#{value}"
|
|
end
|
|
end
|
|
|
|
class WithAfterInitializeMethod < CouchRest::Model::Base
|
|
use_database TEST_SERVER.default_database
|
|
|
|
property :some_value
|
|
|
|
def after_initialize
|
|
self.some_value ||= "value"
|
|
end
|
|
|
|
end
|
|
|
|
|