Module: SimplyStored::Couch::ClassMethods
Instance Method Summary
collapse
#define_attachment_accessors, #has_s3_attachment
Methods included from FindBy
#_define_count_by, #_define_find_all_by, #_define_find_by
Methods included from Finders
#all, #count, #find, #first, #last
Methods included from HasOne
#define_has_one_getter, #define_has_one_setter, #has_one, #set_parent_has_one_association_object
#define_has_and_belongs_to_many_after_destroy_cleanup, #define_has_and_belongs_to_many_count, #define_has_and_belongs_to_many_getter, #define_has_and_belongs_to_many_property, #define_has_and_belongs_to_many_setter_add, #define_has_and_belongs_to_many_setter_remove, #define_has_and_belongs_to_many_setter_remove_all, #define_has_and_belongs_to_many_views, #has_and_belongs_to_many
Methods included from HasMany
#define_has_many_count, #define_has_many_getter, #define_has_many_setter_add, #define_has_many_setter_remove, #define_has_many_setter_remove_all, #define_has_many_through_getter, #has_many, #set_parent_has_many_association_object
Methods included from BelongsTo
#belongs_to
Methods included from Properties
#check_existing_properties
#validates_format_of, #validates_inclusion_of, #validates_uniqueness_of
#_find_property, #attr_accessible, #attr_protected, #foreign_key, #foreign_property, #get_class_from_name
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/simply_stored/couch.rb', line 87
def method_missing(name, *args)
if name.to_s =~ /^find_by/
_define_find_by(name, *args)
elsif name.to_s =~ /^find_all_by/
_define_find_all_by(name, *args)
elsif name.to_s =~ /^count_by/
_define_count_by(name, *args)
else
super
end
end
|
Instance Method Details
#_define_cache_accessors(name, options) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/simply_stored/couch.rb', line 113
def _define_cache_accessors(name, options)
define_method "_get_cached_#{name}" do
instance_variable_get("@#{name}") || {}
end
define_method "_set_cached_#{name}" do |value, cache_key|
cached = send("_get_cached_#{name}")
cached[cache_key] = value
instance_variable_set("@#{name}", cached)
end
define_method "_cache_key_for" do |opt|
opt.blank? ? :all : opt.to_s
end
end
|
#_define_hard_delete_methods ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/simply_stored/couch.rb', line 99
def _define_hard_delete_methods
define_method("destroy!") do
destroy(true)
end
define_method("delete!") do
destroy(true)
end
end
|
#_define_soft_delete_views ⇒ Object
#auto_conflict_resolution_on_save ⇒ Object
79
80
81
|
# File 'lib/simply_stored/couch.rb', line 79
def auto_conflict_resolution_on_save
@auto_conflict_resolution_on_save.nil? ? true : @auto_conflict_resolution_on_save
end
|
#auto_conflict_resolution_on_save=(val) ⇒ Object
83
84
85
|
# File 'lib/simply_stored/couch.rb', line 83
def auto_conflict_resolution_on_save=(val)
@auto_conflict_resolution_on_save = val
end
|
#create(attributes = {}, &blk) ⇒ Object
52
53
54
55
56
|
# File 'lib/simply_stored/couch.rb', line 52
def create(attributes = {}, &blk)
instance = new(attributes, &blk)
instance.save
instance
end
|
#create!(attributes = {}, &blk) ⇒ Object
58
59
60
61
62
|
# File 'lib/simply_stored/couch.rb', line 58
def create!(attributes = {}, &blk)
instance = new(attributes, &blk)
instance.save!
instance
end
|
#enable_soft_delete(property_name = :deleted_at) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/simply_stored/couch.rb', line 64
def enable_soft_delete(property_name = :deleted_at)
@_soft_delete_attribute = property_name.to_sym
property property_name, :type => Time
_define_hard_delete_methods
_define_soft_delete_views
end
|
#soft_delete_attribute ⇒ Object
71
72
73
|
# File 'lib/simply_stored/couch.rb', line 71
def soft_delete_attribute
@_soft_delete_attribute
end
|
#soft_deleting_enabled? ⇒ Boolean
75
76
77
|
# File 'lib/simply_stored/couch.rb', line 75
def soft_deleting_enabled?
!soft_delete_attribute.nil?
end
|