Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ $ rails generate couchrest_model:config
$ rails generate model person --orm=couchrest_model
```

## General Usage
## General Usage

```ruby
require 'couchrest_model'
Expand Down
4 changes: 2 additions & 2 deletions THANKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CouchRest THANKS
=====================

CouchRest was originally developed by J. Chris Anderson <jchris@grabb.it>
and a number of other contributors. Many people further contributed to
and a number of other contributors. Many people further contributed to
CouchRest by reporting problems, suggesting various improvements or submitting
changes. A list of these people is included below.

Expand All @@ -15,7 +15,7 @@ changes. A list of these people is included below.
* [Marcos Tapajós](http://tapajos.me)
* [Sam Lown](http://github.com/samlown)
* [Will Leinweber](http://github.com/will)

Patches are welcome. The primary source for this software project is [on Github](http://github.com/couchrest/couchrest)

A lot of people have active forks - thank you all - even the patches I don't end up using are helpful.
6 changes: 3 additions & 3 deletions benchmarks/dirty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class BenchmarkCasted < Hash
include CouchRest::Model::CastedModel

property :name
end

Expand Down Expand Up @@ -86,11 +86,11 @@ def run_benchmark
if ENV['BENCHMARK_DB']
# db writing
x.report("write changed record to db") do
db_n.times { |i| b.string = "test#{i}"; b.save }
db_n.times { |i| b.string = "test#{i}"; b.save }
end

x.report("write unchanged record to db") do
db_n.times { b.save }
db_n.times { b.save }
end

# db reading
Expand Down
6 changes: 3 additions & 3 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@
* Support typecasting `Symbol`
* Added `:array` option to properties
* Typecasting Dates, Times, and Booleans, with invalid values returns nil

* API Breaking Changes
* Properties with blocks are now singular unless the `array: true` option is passed.


## 1.2.0.beta - 2012-06-08

Expand Down Expand Up @@ -217,7 +217,7 @@ Notes:
## CouchRest Model 1.0.0.beta8

* Major enhancements
* Added model generator
* Added model generator

* Minor enhancements
* Raise error on adding objects to "collection_of" without an id
Expand Down
6 changes: 3 additions & 3 deletions lib/couchrest/model/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ module ClassMethods
# An attribute will be created matching the name of the attribute
# with '_id' on the end, or the foreign key (:foreign_key) provided.
#
# Searching for the assocated object is performed using a string
# Searching for the assocated object is performed using a string
# (:proxy) to be evaulated in the context of the owner. Typically
# this will be set to the class name (:class_name), or determined
# automatically if the owner belongs to a proxy object.
#
# If the association owner is proxied by another model, than an attempt will
# be made to automatically determine the correct place to request
# the documents. Typically, this is a method with the pluralized name of the
# the documents. Typically, this is a method with the pluralized name of the
# association inside owner's owner, or proxy.
#
# For example, imagine a company acts as a proxy for invoices and clients.
Expand All @@ -28,7 +28,7 @@ module ClassMethods
#
# self.company.clients
#
# If the name of the collection proxy is not the pluralized assocation name,
# If the name of the collection proxy is not the pluralized assocation name,
# it can be set with the :proxy_name option.
#
def belongs_to(attrib, *options)
Expand Down
8 changes: 4 additions & 4 deletions lib/couchrest/model/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Base < CouchRest::Document
include Designs
include CastedBy
include Dirty


def self.subclasses
@subclasses ||= []
Expand Down Expand Up @@ -76,13 +76,13 @@ def self.build(attrs = {}, options = {}, &block)
alias :new_record? :new?
alias :new_document? :new?

# Compare this model with another by confirming to see
# Compare this model with another by confirming to see
# if the IDs and their databases match!
#
# Camparison of the database is required in case the
# Camparison of the database is required in case the
# model has been proxied or loaded elsewhere.
#
# A Basic CouchRest document will only ever compare using
# A Basic CouchRest document will only ever compare using
# a Hash comparison on the attributes.
def == other
return false unless other.is_a?(Base)
Expand Down
4 changes: 2 additions & 2 deletions lib/couchrest/model/designs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module ClassMethods
# Adding a prefix allows you to associate multiple design documents with the same
# model. This is useful if you'd like to split your designs into seperate
# use cases; one for regular search functions and a second for stats for example.
#
#
# # Create a design doc with id _design/Cats
# design do
# view :by_name
Expand Down Expand Up @@ -100,7 +100,7 @@ def prepare_design_options(*args)
end

def prepare_source_paths(options)

end

end
Expand Down
10 changes: 5 additions & 5 deletions lib/couchrest/model/extended_attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create_attachment(args={})
rescue ArgumentError
raise ArgumentError, 'You must specify :file and :name'
end

# return all attachments
def attachments
self['_attachments'] ||= {}
Expand Down Expand Up @@ -51,15 +51,15 @@ def attachment_url(attachment_name)
return unless has_attachment?(attachment_name)
"#{database.root}/#{self.id}/#{attachment_name}"
end

# returns URI to fetch the attachment from
def attachment_uri(attachment_name)
return unless has_attachment?(attachment_name)
"#{database.uri}/#{self.id}/#{attachment_name}"
end

private

def get_mime_type(path)
return nil if path.nil?
type = ::MIME::Types.type_for(path)
Expand All @@ -75,7 +75,7 @@ def set_attachment_attr(args)
'data' => args[:file].read
}
end

end # module ExtendedAttachments
end
end
6 changes: 3 additions & 3 deletions lib/couchrest/model/properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def directly_set_attributes(hash, mass_assign = false)
multi_parameter_attributes << [ key, value ]
false
elsif self.respond_to?("#{key}=")
self.send("#{key}=", value)
self.send("#{key}=", value)
elsif mass_assign || mass_assign_any_attribute
self[key] = value
end
Expand Down Expand Up @@ -131,7 +131,7 @@ def assign_multiparameter_attributes(pairs, hash)
def execute_callstack_for_multiparameter_attributes(callstack, hash)
callstack.each do |name, values_with_empty_parameters|
if self.respond_to?("#{name}=")
casted_attrib = send("#{name}=", values_with_empty_parameters)
casted_attrib = send("#{name}=", values_with_empty_parameters)
unless casted_attrib.is_a?(Hash)
hash.reject { |key, value| key.include?(name.to_s)}
end
Expand Down Expand Up @@ -177,7 +177,7 @@ def property(name, *options, &block)

# Automatically set <tt>updated_at</tt> and <tt>created_at</tt> fields
# on the document whenever saving occurs.
#
#
# These properties are casted as Time objects, so they should always
# be set to UTC.
def timestamps!
Expand Down
4 changes: 2 additions & 2 deletions lib/couchrest/model/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(name, options = {}, &block)
def to_s
name
end

def to_sym
@_sym_name ||= name.to_sym
end
Expand Down Expand Up @@ -65,7 +65,7 @@ def default_value
end

# Initialize a new instance of a property's type ready to be
# used. If a proc is defined for the init method, it will be used instead of
# used. If a proc is defined for the init method, it will be used instead of
# a normal call to the class.
def build(*args)
raise StandardError, "Cannot build property without a class" if @type.nil?
Expand Down
2 changes: 1 addition & 1 deletion lib/couchrest/model/support/couchrest_database.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Extend CouchRest's normal database delete! method to ensure any caches are
# also emptied. Given that this is a rare event, and the consequences are not
# also emptied. Given that this is a rare event, and the consequences are not
# very severe, we just completely empty the cache.
#
module CouchRest::Model
Expand Down
1 change: 0 additions & 1 deletion lib/couchrest/model/validations/casted_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module CouchRest
module Model
module Validations
class CastedModelValidator < ActiveModel::EachValidator

def validate_each(document, attribute, value)
values = value.is_a?(Array) ? value : [value]
return if values.collect {|doc| doc.nil? || doc.valid? }.all?
Expand Down
2 changes: 0 additions & 2 deletions lib/rails/generators/couchrest_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
module CouchrestModel
module Generators
class Base < Rails::Generators::NamedBase #:nodoc:

# Set the current directory as base for the inherited generators.
def self.base_root
File.dirname(__FILE__)
end

end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create_module_file
return if class_path.empty?
template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
end

hook_for :test_framework

protected
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Basic < CouchRest::Model::Base
end

def reset_test_db!
DB.recreate! rescue nil
DB.recreate! rescue nil
# Reset the Design Cache
Thread.current[:couchrest_design_cache] = {}
DB
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/assocations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def SaleInvoice.merge_assoc_opts(*args)
o = SaleInvoice.merge_assoc_opts(:cat)
expect(o[:proxy]).to eql('self.company.cats')
end

end

describe "of type belongs to" do
Expand Down
Loading