Merge branch 'master' of github.com:couchrest/couchrest_model

Conflicts:
	lib/couchrest/model/properties.rb
This commit is contained in:
Sam Lown 2011-05-19 00:10:18 +02:00
commit 9754f4633c
6 changed files with 23 additions and 33 deletions

View file

@ -1,21 +1,18 @@
require 'rubygems'
require 'bundler'
Bundler::GemHelper.install_tasks
require 'rake'
require 'rspec/core/rake_task'
require "rake/rdoctask"
require 'rspec'
require 'rspec/core/rake_task'
Bundler::GemHelper.install_tasks
desc "Run all specs"
Rspec::Core::RakeTask.new(:spec) do |spec|
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.rspec_opts = ["--color"]
spec.pattern = 'spec/**/*_spec.rb'
end
desc "Print specdocs"
Rspec::Core::RakeTask.new(:doc) do |spec|
RSpec::Core::RakeTask.new(:doc) do |spec|
spec.rspec_opts = ["--format", "specdoc"]
spec.pattern = 'spec/*_spec.rb'
end

View file

@ -25,9 +25,8 @@ Gem::Specification.new do |s|
s.add_dependency(%q<couchrest>, "1.1.0.pre2")
s.add_dependency(%q<mime-types>, "~> 1.15")
s.add_dependency(%q<activemodel>, "~> 3.0.0")
s.add_dependency(%q<activemodel>, "~> 3.0")
s.add_dependency(%q<tzinfo>, "~> 0.3.22")
s.add_dependency(%q<railties>, "~> 3.0.0")
s.add_development_dependency(%q<rspec>, ">= 2.0.0")
s.add_development_dependency(%q<rack-test>, ">= 0.5.7")
# s.add_development_dependency("jruby-openssl", ">= 0.7.3")

View file

@ -49,6 +49,8 @@ module CouchRest
# * :directly_set_attributes: true when data comes directly from database
# * :database: provide an alternative database
#
# If a block is provided the new model will be passed into the
# block so that it can be populated.
def initialize(doc = {}, options = {})
doc = prepare_all_attributes(doc, options)
# set the instances database, if provided
@ -57,6 +59,8 @@ module CouchRest
unless self['_id'] && self['_rev']
self[self.model_type_key] = self.class.to_s
end
yield self if block_given?
after_initialize if respond_to?(:after_initialize)
end

View file

@ -5,8 +5,8 @@ module CouchRest
extend ActiveSupport::Concern
included do
extlib_inheritable_accessor(:properties) unless self.respond_to?(:properties)
extlib_inheritable_accessor(:properties_by_name) unless self.respond_to?(:properties_by_name)
class_attribute(:properties) unless self.respond_to?(:properties)
class_attribute(:properties_by_name) unless self.respond_to?(:properties_by_name)
self.properties ||= []
self.properties_by_name ||= {}
raise "You can only mixin Properties in a class responding to [] and []=, if you tried to mixin CastedModel, make sure your class inherits from Hash or responds to the proper methods" unless (method_defined?(:[]) && method_defined?(:[]=))
@ -16,20 +16,6 @@ module CouchRest
Hash[self].reject{|k,v| v.nil?}.as_json(options)
end
# Returns the Class properties
#
# ==== Returns
# Array:: the list of properties for model's class
def properties
self.class.properties
end
# Returns all the class's properties as a Hash where the key is the name
# of the property.
def properties_by_name
self.class.properties_by_name
end
# Returns the Class properties with their values
#
# ==== Returns

View file

@ -1,7 +1,6 @@
require 'active_model'
require "active_model/callbacks"
require "active_model/conversion"
require "active_model/deprecated_error_methods"
require "active_model/errors"
require "active_model/naming"
require "active_model/serialization"

View file

@ -44,6 +44,11 @@ describe "Model Base" do
@obj.database.should eql('database')
end
it "should support initialization block" do
@obj = Basic.new {|b| b.database = 'database'}
@obj.database.should eql('database')
end
end
describe "ActiveModel compatability Basic" do