Merge branch 'master' of github.com:couchrest/couchrest_model
Conflicts: lib/couchrest/model/properties.rb
This commit is contained in:
commit
9754f4633c
6 changed files with 23 additions and 33 deletions
21
Rakefile
21
Rakefile
|
@ -1,23 +1,20 @@
|
|||
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|
|
||||
spec.rspec_opts = ["--color"]
|
||||
spec.pattern = 'spec/**/*_spec.rb'
|
||||
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|
|
||||
spec.rspec_opts = ["--format", "specdoc"]
|
||||
spec.pattern = 'spec/*_spec.rb'
|
||||
RSpec::Core::RakeTask.new(:doc) do |spec|
|
||||
spec.rspec_opts = ["--format", "specdoc"]
|
||||
spec.pattern = 'spec/*_spec.rb'
|
||||
end
|
||||
|
||||
desc "Generate the rdoc"
|
||||
|
@ -38,4 +35,4 @@ module Rake
|
|||
end
|
||||
|
||||
Rake.remove_task("github:release")
|
||||
Rake.remove_task("release")
|
||||
Rake.remove_task("release")
|
|
@ -17,17 +17,16 @@ Gem::Specification.new do |s|
|
|||
s.homepage = %q{http://github.com/couchrest/couchrest_model}
|
||||
s.rubygems_version = %q{1.3.7}
|
||||
s.summary = %q{Extends the CouchRest Document for advanced modelling.}
|
||||
|
||||
|
||||
s.files = `git ls-files`.split("\n")
|
||||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
||||
s.require_paths = ["lib"]
|
||||
|
||||
|
||||
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")
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue