From 7f1f05cbca6918cdd3842ad3a5483221ebec5440 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Fri, 6 May 2011 11:23:14 -0700 Subject: [PATCH 1/6] Dumped supported rails versions --- couchrest_model.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/couchrest_model.gemspec b/couchrest_model.gemspec index 6a8947f..8d54a83 100644 --- a/couchrest_model.gemspec +++ b/couchrest_model.gemspec @@ -25,9 +25,9 @@ Gem::Specification.new do |s| s.add_dependency(%q, "1.1.0.pre2") s.add_dependency(%q, "~> 1.15") - s.add_dependency(%q, "~> 3.0.0") + s.add_dependency(%q, "~> 3.0") s.add_dependency(%q, "~> 0.3.22") - s.add_dependency(%q, "~> 3.0.0") + s.add_dependency(%q, "~> 3.0") s.add_development_dependency(%q, ">= 2.0.0") s.add_development_dependency(%q, ">= 0.5.7") # s.add_development_dependency("jruby-openssl", ">= 0.7.3") From 2b0dc2b779a8f3788dfe5523c4d9ccbd77d9fb5e Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Fri, 6 May 2011 13:32:49 -0700 Subject: [PATCH 2/6] Removed unneeded require --- lib/couchrest_model.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/couchrest_model.rb b/lib/couchrest_model.rb index 7de6b41..8892ea4 100644 --- a/lib/couchrest_model.rb +++ b/lib/couchrest_model.rb @@ -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" From 2669de9511d95c8d13205dfd39355cdcc553d395 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Mon, 9 May 2011 09:47:27 -0600 Subject: [PATCH 3/6] Use class_attribute rather than extlib_inheritable_attribute (which is removed in rails 3.1) --- lib/couchrest/model/properties.rb | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/lib/couchrest/model/properties.rb b/lib/couchrest/model/properties.rb index 229c5bc..7f78444 100644 --- a/lib/couchrest/model/properties.rb +++ b/lib/couchrest/model/properties.rb @@ -5,26 +5,13 @@ 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?(:[]=)) 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 # From c9d2611bb7bd09b0ed7e8962d0f578f841d17b40 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 11 May 2011 13:53:28 -0600 Subject: [PATCH 4/6] Support providing an initialization block when creating new models --- lib/couchrest/model/base.rb | 4 ++++ spec/couchrest/base_spec.rb | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/couchrest/model/base.rb b/lib/couchrest/model/base.rb index 0f6d26c..5f3a6cd 100644 --- a/lib/couchrest/model/base.rb +++ b/lib/couchrest/model/base.rb @@ -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 diff --git a/spec/couchrest/base_spec.rb b/spec/couchrest/base_spec.rb index 21c9a40..208d6e7 100644 --- a/spec/couchrest/base_spec.rb +++ b/spec/couchrest/base_spec.rb @@ -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 From 14e96367a5e518e4b14df28b4ff49308e70d4357 Mon Sep 17 00:00:00 2001 From: Davide D'Agostino Date: Mon, 16 May 2011 10:50:00 +0200 Subject: [PATCH 5/6] Remove dependency of railties, issue #69 --- couchrest_model.gemspec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/couchrest_model.gemspec b/couchrest_model.gemspec index 8d54a83..ce7f2ab 100644 --- a/couchrest_model.gemspec +++ b/couchrest_model.gemspec @@ -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, "1.1.0.pre2") s.add_dependency(%q, "~> 1.15") s.add_dependency(%q, "~> 3.0") s.add_dependency(%q, "~> 0.3.22") - s.add_dependency(%q, "~> 3.0") s.add_development_dependency(%q, ">= 2.0.0") s.add_development_dependency(%q, ">= 0.5.7") # s.add_development_dependency("jruby-openssl", ">= 0.7.3") From f8769400b64c7852599949607785f5ad5563c53d Mon Sep 17 00:00:00 2001 From: Davide D'Agostino Date: Mon, 16 May 2011 10:50:22 +0200 Subject: [PATCH 6/6] Update Rakefile to use latest rspec. --- Rakefile | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Rakefile b/Rakefile index 8cf05ec..f624098 100644 --- a/Rakefile +++ b/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") \ No newline at end of file