Module: SimplyCouch::Model

Defined in:
lib/simply_couch/model.rb,
lib/simply_couch/model/find_by.rb,
lib/simply_couch/model/finders.rb,
lib/simply_couch/model/has_one.rb,
lib/simply_couch/model/ancestry.rb,
lib/simply_couch/model/database.rb,
lib/simply_couch/model/has_many.rb,
lib/simply_couch/model/belongs_to.rb,
lib/simply_couch/model/pagination.rb,
lib/simply_couch/model/properties.rb,
lib/simply_couch/model/view/lists.rb,
lib/simply_couch/model/attachments.rb,
lib/simply_couch/model/embedded_in.rb,
lib/simply_couch/model/persistence.rb,
lib/simply_couch/model/validations.rb,
lib/simply_couch/model/view/view_query.rb,
lib/simply_couch/model/has_many_embedded.rb,
lib/simply_couch/model/view/custom_views.rb,
lib/simply_couch/model/pagination_options.rb,
lib/simply_couch/model/view/raw_view_spec.rb,
lib/simply_couch/model/view/base_view_spec.rb,
lib/simply_couch/model/association_property.rb,
lib/simply_couch/model/view/model_view_spec.rb,
lib/simply_couch/model/view/custom_view_spec.rb,
lib/simply_couch/model/has_and_belongs_to_many.rb,
lib/simply_couch/model/view/properties_view_spec.rb,
lib/simply_couch/model/views/deleted_model_view_spec.rb,
lib/simply_couch/model/views/array_property_view_spec.rb

Defined Under Namespace

Modules: Ancestry, Attachments, BelongsTo, ClassMethods, Database, EmbeddedIn, FindBy, Finders, HasAndBelongsToMany, HasMany, HasManyEmbedded, HasOne, Pagination, PaginationOptions, Persistence, Properties, Validations, View, Views Classes: AssociationProperty, DatabaseInstance

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.compact_all_design_documents(database) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/simply_couch/model.rb', line 181

def self.compact_all_design_documents(database)
  db = CouchRest.database(database)
  db.info # ensure DB exists
  design_docs = CouchRest.get("#{database}/_all_docs?startkey=%22_design%22&endkey=%22_design0%22")['rows'].map do |row|
    [row['id'], row['value']['rev']]
  end
  design_docs.each do |doc_id, rev|
    puts "#{database}/_compact/#{doc_id.gsub("_design/",'')}"
    CouchRest.post("#{database}/_compact/#{doc_id.gsub("_design/",'')}")
  end
  design_docs.size
end

.delete_all_design_documents(database) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/simply_couch/model.rb', line 169

def self.delete_all_design_documents(database)
  db = CouchRest.database(database)
  db.info # ensure DB exists
  design_docs = CouchRest.get("#{database}/_all_docs?startkey=%22_design%22&endkey=%22_design0%22")['rows'].map do |row|
    [row['id'], row['value']['rev']]
  end
  design_docs.each do |doc_id, rev|
    db.delete_doc({'_id' => doc_id, '_rev' => rev})
  end
  design_docs.size
end

.included(clazz) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/simply_couch/model.rb', line 36

def self.included(clazz)
  clazz.send(:include, Persistence)
  clazz.send(:include, InstanceMethods)
  clazz.send(:extend, ClassMethods)

  clazz.instance_eval do
    attr_accessor :_accessible_attributes, :_protected_attributes

    view :all_documents, :key => :created_at
  end
end

Instance Method Details

#extract_association_options(local_options = nil) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/simply_couch/model.rb', line 151

def extract_association_options(local_options = nil)
  forced_reload = false
  with_deleted = false
  limit = nil
  descending = false
  skip = nil

  if local_options
    local_options.assert_valid_keys(:force_reload, :with_deleted, :limit, :order)
    forced_reload = local_options.delete(:force_reload)
    with_deleted = local_options[:with_deleted]
    limit = local_options[:limit]
    descending = (local_options[:order] == :desc) ? true : false
    skip = local_options[:skip]
  end
  return [forced_reload, with_deleted, limit, descending, skip]
end