From 2ea8a108b64fd7129fd9c1186533c0aa7f445e98 Mon Sep 17 00:00:00 2001 From: Michael Johnston Date: Thu, 11 Oct 2012 00:30:55 -0700 Subject: [PATCH 1/2] fix for activemodel 3.2 support (still works on 3.0) --- gitmodel.gemspec | 4 ++-- lib/gitmodel/persistable.rb | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/gitmodel.gemspec b/gitmodel.gemspec index dad2fe7..49b0231 100644 --- a/gitmodel.gemspec +++ b/gitmodel.gemspec @@ -17,8 +17,8 @@ Gem::Specification.new do |s| of all changes. DESC - s.add_dependency 'activemodel', '~> 3.0.1' - s.add_dependency 'activesupport', '~> 3.0.1' + s.add_dependency 'activemodel', '>= 3.0.1' + s.add_dependency 'activesupport', '>= 3.0.1' s.add_dependency 'dalli' s.add_dependency 'grit', '>= 2.3.0' s.add_dependency 'lockfile', '>= 1.4.3' diff --git a/lib/gitmodel/persistable.rb b/lib/gitmodel/persistable.rb index ed03436..cad5a5f 100644 --- a/lib/gitmodel/persistable.rb +++ b/lib/gitmodel/persistable.rb @@ -23,14 +23,13 @@ def self.included(base) def initialize(args = {}) - _run_initialize_callbacks do - @new_record = true - self.attributes = {} - self.blobs = {} - args.each do |k,v| - self.send("#{k}=".to_sym, v) - end + @new_record = true + self.attributes = {} + self.blobs = {} + args.each do |k,v| + self.send("#{k}=".to_sym, v) end + run_callbacks :initialize end def to_model @@ -333,7 +332,7 @@ def find_all(conditions = {}) def all_values_for_attr(attr) attr_index = index.attr_index(attr.to_s) - values = attr_index ? attr_index.keys : [] + attr_index ? attr_index.keys : [] end def create(args) @@ -360,7 +359,7 @@ def delete(id, options = {}) GitModel.logger.debug "Deleting #{name} with id: #{id}" path = File.join(db_subdir, id) transaction = options.delete(:transaction) || GitModel::Transaction.new(options) - result = transaction.execute do |t| + transaction.execute do |t| branch = t.branch || options[:branch] || GitModel.default_branch delete_tree(path, t.index, branch, options) end @@ -369,7 +368,7 @@ def delete(id, options = {}) def delete_all(options = {}) GitModel.logger.debug "Deleting all #{name.pluralize}" transaction = options.delete(:transaction) || GitModel::Transaction.new(options) - result = transaction.execute do |t| + transaction.execute do |t| branch = t.branch || options[:branch] || GitModel.default_branch delete_tree(db_subdir, t.index, branch, options) end From df070f6ef3d015c43e513927b0d1dad97a9ff712 Mon Sep 17 00:00:00 2001 From: Michael Johnston Date: Thu, 11 Oct 2012 00:39:11 -0700 Subject: [PATCH 2/2] update other run_callbacks calls too --- lib/gitmodel/persistable.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gitmodel/persistable.rb b/lib/gitmodel/persistable.rb index cad5a5f..0e15c18 100644 --- a/lib/gitmodel/persistable.rb +++ b/lib/gitmodel/persistable.rb @@ -107,7 +107,7 @@ def persisted? # :commit_message # Returns false if validations failed, otherwise returns the SHA of the commit def save(options = {}) - _run_save_callbacks do + run_callbacks(:save) do raise GitModel::NullId unless self.id if new_record? @@ -168,7 +168,7 @@ def to_s private def load(dir, branch) - _run_find_callbacks do + run_callbacks(:find) do # remove dangerous ".." # todo find a better way to ensure path is safe dir.gsub!(/\.\./, '')