Permalink
Browse files

Fixing gem loading issues on Ruby 1.9.x - favoring Rails project gem …

…version first, otherwise try load the gem from the plugin.
  • Loading branch information...
1 parent 8292606 commit 0d54901a309113269a73d52af9fa698693e74625 @grimen grimen committed Oct 2, 2009
Showing with 33 additions and 9 deletions.
  1. +7 −1 Rakefile
  2. +8 −5 lib/validation_reflection.rb
  3. +1 −0 rails/init.rb
  4. +16 −3 test/test_helper.rb
  5. +1 −0 test/validation_reflection_test.rb
View
@@ -1,3 +1,4 @@
+# encoding: utf-8
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
@@ -22,7 +23,12 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
end
begin
- require 'jeweler'
+ begin
+ require 'jeweler'
+ rescue LoadError
+ gem 'technicalpickles-jeweler', '>= 1.0.0'
+ require 'jeweler'
+ end
Jeweler::Tasks.new do |gemspec|
gemspec.name = "validation_reflection"
gemspec.summary = "Adds reflective access to validations"
@@ -1,3 +1,4 @@
+# encoding: utf-8
#--
# Copyright (c) 2006-2008, Michael Schuerig, michael@schuerig.de
#
@@ -58,7 +59,7 @@ def included(base)
def load_config
if ::File.file?(CONFIG_PATH)
config = ::OpenStruct.new
- config.reflected_validations = reflected_validations
+ config.reflected_validations = @@reflected_validations
silence_warnings do
eval(::IO.read(CONFIG_PATH), binding, CONFIG_PATH)
end
@@ -109,25 +110,27 @@ def reflect_on_validations_for(attr_name)
end
private
-
+
+ # Store validation info for easy and fast access.
+ #
def remember_validation_metadata(validation_type, *attr_names)
configuration = attr_names.last.is_a?(::Hash) ? attr_names.pop : {}
attr_names.each do |attr_name|
self.write_inheritable_array :validations,
[::ActiveRecord::Reflection::MacroReflection.new(validation_type, attr_name.to_sym, configuration, self)]
end
end
-
+
def ignoring_subvalidations(ignore)
save_ignore = self.in_ignored_subvalidation
- unless in_ignored_subvalidation
+ unless self.in_ignored_subvalidation
self.in_ignored_subvalidation = ignore
yield
end
ensure
self.in_ignored_subvalidation = save_ignore
end
-
+
end
end
end
View
@@ -1 +1,2 @@
+# encoding: utf-8
require 'validation_reflection'
View
@@ -1,6 +1,19 @@
-ENV["RAILS_ENV"] = "test"
+# encoding: utf-8
+ENV['RAILS_ENV'] = 'test'
RAILS_ROOT = File.join(File.dirname(__FILE__))
require 'rubygems'
-require 'test/unit'
-require 'active_record'
+
+begin
+ require 'active_record'
+rescue LoadError
+ gem 'activerecord', '>= 1.2.3'
+ require 'active_record'
+end
+
+begin
+ require 'test/unit'
+rescue LoadError
+ gem 'test-unit', '>= 1.2.3'
+ require 'test/unit'
+end
@@ -1,3 +1,4 @@
+# encoding: utf-8
require File.join(File.dirname(__FILE__), 'test_helper')
ActiveRecord::Base.class_eval do

0 comments on commit 0d54901

Please sign in to comment.