Permalink
Browse files

Moving back to plugin cache for ActiveRecord

This simplifies the code a lot and fixes the issues with date and time
colummns when using the plugin parser.

Add appraisals for all rails 3 versions
  • Loading branch information...
1 parent 62557e7 commit 973bbfa82c2074a1c06861458243845a6ae8f599 @adzap committed Aug 19, 2012
Showing with 66 additions and 43 deletions.
  1. +11 −0 Appraisals
  2. +2 −0 Gemfile
  3. +4 −2 Rakefile
  4. +15 −0 gemfiles/rails_3_0.gemfile
  5. +15 −0 gemfiles/rails_3_1.gemfile
  6. +15 −0 gemfiles/rails_3_2.gemfile
  7. +4 −41 lib/validates_timeliness/orm/active_record.rb
View
@@ -0,0 +1,11 @@
+appraise "rails_3_0" do
+ gem "rails", "~> 3.0.0"
+end
+
+appraise "rails_3_1" do
+ gem "rails", "~> 3.1.0"
+end
+
+appraise "rails_3_2" do
+ gem "rails", "~> 3.2.0"
+end
View
@@ -9,6 +9,8 @@ gem 'timecop'
gem 'rspec_tag_matchers'
gem 'ruby-debug', :platforms => [:ruby_18, :jruby]
gem 'debugger', :platforms => [:ruby_19]
+gem 'appraisal'
+gem 'sqlite3'
group :mongoid do
gem 'mongoid', '~> 2.3.0'
View
@@ -1,7 +1,9 @@
require 'bundler'
-Bundler::GemHelper.install_tasks
+require 'bundler/setup'
+
+require 'appraisal'
-Bundler.setup
+Bundler::GemHelper.install_tasks
require 'rake/rdoctask'
require 'rspec/core/rake_task'
View
@@ -0,0 +1,15 @@
+# This file was generated by Appraisal
+
+source "http://rubygems.org"
+
+gem "rspec", "~> 2.8"
+gem "rspec-rails", "~> 2.8"
+gem "timecop"
+gem "rspec_tag_matchers"
+gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
+gem "debugger", :platforms=>[:ruby_19]
+gem "appraisal"
+gem "sqlite3"
+gem "rails", "~> 3.0.0"
+
+gemspec :path=>"../"
View
@@ -0,0 +1,15 @@
+# This file was generated by Appraisal
+
+source "http://rubygems.org"
+
+gem "rspec", "~> 2.8"
+gem "rspec-rails", "~> 2.8"
+gem "timecop"
+gem "rspec_tag_matchers"
+gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
+gem "debugger", :platforms=>[:ruby_19]
+gem "appraisal"
+gem "sqlite3"
+gem "rails", "~> 3.1.0"
+
+gemspec :path=>"../"
View
@@ -0,0 +1,15 @@
+# This file was generated by Appraisal
+
+source "http://rubygems.org"
+
+gem "rspec", "~> 2.8"
+gem "rspec-rails", "~> 2.8"
+gem "timecop"
+gem "rspec_tag_matchers"
+gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
+gem "debugger", :platforms=>[:ruby_19]
+gem "appraisal"
+gem "sqlite3"
+gem "rails", "~> 3.2.0"
+
+gemspec :path=>"../"
@@ -3,19 +3,6 @@ module ORM
module ActiveRecord
extend ActiveSupport::Concern
- def self.use_plugin_cache?
- ::ActiveRecord::VERSION::STRING < '3.1.0'
- end
-
- included do
- if ValidatesTimeliness::ORM::ActiveRecord.use_plugin_cache?
- include Reload
- else
- # Just use the built-in before_type_cast retrieval
- alias_method :_timeliness_raw_value_for, :read_attribute_before_type_cast
- end
- end
-
module ClassMethods
public
@@ -36,34 +23,12 @@ def timeliness_column_for_attribute(attr_name)
def define_attribute_methods
super.tap do |attribute_methods_generated|
- use_before_type_cast = ValidatesTimeliness::ORM::ActiveRecord.use_plugin_cache?
- define_timeliness_methods use_before_type_cast
+ define_timeliness_methods true
end
end
protected
- def define_attribute_timeliness_methods(attr_name, before_type_cast=false)
- if before_type_cast
- define_timeliness_write_method(attr_name)
- define_timeliness_before_type_cast_method(attr_name)
- elsif ValidatesTimeliness.use_plugin_parser
- define_timeliness_write_method_without_cache(attr_name)
- end
- end
-
- def define_timeliness_write_method_without_cache(attr_name)
- method_body, line = <<-EOV, __LINE__ + 1
- def #{attr_name}=(value)
- original_value = value
- if value.is_a?(String)\n#{timeliness_type_cast_code(attr_name, 'value')}\nend
- super(value)
- @attributes['#{attr_name}'] = original_value
- end
- EOV
- generated_timeliness_methods.module_eval(method_body, __FILE__, line)
- end
-
def timeliness_type_cast_code(attr_name, var_name)
type = timeliness_attribute_type(attr_name)
@@ -73,11 +38,9 @@ def timeliness_type_cast_code(attr_name, var_name)
end
end
- module Reload
- def reload(*args)
- _clear_timeliness_cache
- super
- end
+ def reload(*args)
+ _clear_timeliness_cache
+ super
end
end

0 comments on commit 973bbfa

Please sign in to comment.