Module: SimplyCouch::Model::ClassMethods

Instance Method Summary collapse

Methods included from Ancestry

ancestry_by_property, #has_ancestry

Methods included from Storage::ClassMethods

#define_attachment_accessors, #has_s3_attachment

Methods included from PaginationOptions

#with_pagination_options

Methods included from Pagination

#current_page_method, #num_pages_method, #per_page_method, #total_pages_method

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

Methods included from HasAndBelongsToMany

#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 HasManyEmbedded

#define_has_many_embedded_count, #define_has_many_embedded_getter, #define_has_many_embedded_setter, #define_has_many_embedded_setter_add, #define_has_many_embedded_setter_remove, #define_has_many_embedded_setter_remove_all, #define_reset_index_values, #has_many_embedded, #set_parent_has_many_embedded_association_object

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 EmbeddedIn

#is_embedded_in

Methods included from BelongsTo

#belongs_to

Methods included from Validations

#validates_containment_of, #validates_uniqueness_of

Methods included from Database

#couchrest_database_url, #couchrest_database_url=, #database

Methods included from ClassMethods::Base

#_find_property, #after_commit, #attr_accessible, #attr_protected, #bulk_update, #find_association_class_name, #foreign_key, #foreign_property, #get_class_from_name, #primary_key, #view

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/simply_couch/model.rb', line 108

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



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/simply_couch/model.rb', line 134

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_methodsObject



120
121
122
123
124
125
126
127
128
# File 'lib/simply_couch/model.rb', line 120

def _define_hard_delete_methods
  define_method("destroy!") do
    destroy(true)
  end

  define_method("delete!") do
    destroy(true)
  end
end

#_define_soft_delete_viewsObject



130
131
132
# File 'lib/simply_couch/model.rb', line 130

def _define_soft_delete_views
  view :all_documents_without_deleted, :type => SimplyCouch::Model::Views::DeletedModelViewSpec
end

#auto_conflict_resolution_on_saveObject



100
101
102
# File 'lib/simply_couch/model.rb', line 100

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



104
105
106
# File 'lib/simply_couch/model.rb', line 104

def auto_conflict_resolution_on_save=(val)
  @auto_conflict_resolution_on_save = val
end

#create(attributes = {}, &blk) ⇒ Object



65
66
67
68
69
# File 'lib/simply_couch/model.rb', line 65

def create(attributes = {}, &blk)
  instance = new(attributes, &blk)
  instance.save
  instance
end

#create!(attributes = {}, &blk) ⇒ Object



71
72
73
74
75
# File 'lib/simply_couch/model.rb', line 71

def create!(attributes = {}, &blk)
  instance = new(attributes, &blk)
  instance.save!
  instance
end

#enable_soft_delete(property_name = :deleted_at) ⇒ Object



77
78
79
80
81
82
# File 'lib/simply_couch/model.rb', line 77

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_attributeObject



84
85
86
# File 'lib/simply_couch/model.rb', line 84

def soft_delete_attribute
  @_soft_delete_attribute
end

#soft_deleting_enabled?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/simply_couch/model.rb', line 88

def soft_deleting_enabled?
  !soft_delete_attribute.nil?
end

#split_design_documents?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/simply_couch/model.rb', line 96

def split_design_documents?
  @_split_design_documents || false
end

#split_design_documents_per_view(enabled = true) ⇒ Object



92
93
94
# File 'lib/simply_couch/model.rb', line 92

def split_design_documents_per_view(enabled = true)
  @_split_design_documents = enabled
end