mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
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
This commit is contained in:
parent
62557e7e04
commit
973bbfa82c
11
Appraisals
Normal file
11
Appraisals
Normal file
@ -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
|
||||
2
Gemfile
2
Gemfile
@ -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'
|
||||
|
||||
6
Rakefile
6
Rakefile
@ -1,7 +1,9 @@
|
||||
require 'bundler'
|
||||
Bundler::GemHelper.install_tasks
|
||||
require 'bundler/setup'
|
||||
|
||||
Bundler.setup
|
||||
require 'appraisal'
|
||||
|
||||
Bundler::GemHelper.install_tasks
|
||||
|
||||
require 'rake/rdoctask'
|
||||
require 'rspec/core/rake_task'
|
||||
|
||||
15
gemfiles/rails_3_0.gemfile
Normal file
15
gemfiles/rails_3_0.gemfile
Normal file
@ -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=>"../"
|
||||
15
gemfiles/rails_3_1.gemfile
Normal file
15
gemfiles/rails_3_1.gemfile
Normal file
@ -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=>"../"
|
||||
15
gemfiles/rails_3_2.gemfile
Normal file
15
gemfiles/rails_3_2.gemfile
Normal file
@ -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 ValidatesTimeliness
|
||||
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 @@ module ValidatesTimeliness
|
||||
|
||||
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 @@ module ValidatesTimeliness
|
||||
end
|
||||
end
|
||||
|
||||
module Reload
|
||||
def reload(*args)
|
||||
_clear_timeliness_cache
|
||||
super
|
||||
end
|
||||
def reload(*args)
|
||||
_clear_timeliness_cache
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user