validation_reflection 0.3.8 → 1.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ == 1.0.0-beta4 2010-06-12
2
+ * Changed initialization to reflect new initialization in Rails 3.
3
+
1
4
  == 0.3.7 2010-06-11
2
5
  * Enhancement from Sutto:
3
6
  ** Use Rails.root if available over RAILS_ROOT
data/README CHANGED
@@ -1,7 +1,7 @@
1
1
  Validation Reflection
2
2
  =====================
3
3
 
4
- Version 0.3.7, 2010-06-11
4
+ Version 1.0.0-beta4, 2010-06-12
5
5
 
6
6
  This plugin adds reflective access to validations
7
7
 
@@ -31,9 +31,9 @@ ActiveRecord::Reflection::MacroReflection. For example
31
31
 
32
32
  Usually, all the standard Rails validations are reflected.
33
33
  You can change this -- add or remove validations -- in an
34
- application-specific configuration file,
34
+ application-specific initializer,
35
35
 
36
- config/plugins/validation_reflection.rb
36
+ config/initializers/validation_reflection.rb
37
37
 
38
38
  In that file change config.reflected_validations to suit your
39
39
  needs. Say, you have a custom validation for email addresses,
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :major: 0
3
- :minor: 3
4
- :build:
5
- :patch: 8
2
+ :major: 1
3
+ :minor: 0
4
+ :build: "beta4"
5
+ :patch: 0
@@ -1,126 +1,104 @@
1
- require 'active_record/reflection'
2
1
  require 'ostruct'
3
2
 
4
- # Based on code by Sebastian Kanthak
5
- # See http://dev.rubyonrails.org/ticket/861
6
- #
7
- module ActiveRecordExtensions # :nodoc:
8
- module ValidationReflection # :nodoc:
9
-
10
- extend self
11
-
12
- require_path = ::File.join((defined?(Rails) ? Rails.root : RAILS_ROOT), 'config', '**', 'validation_reflection.rb').to_s rescue ''
13
-
14
- # Look for config/initializer here in:
15
- CONFIG_PATH = ::Dir.glob(require_path).first || ''
16
- CORE_VALIDATONS = [
17
- :validates_acceptance_of,
18
- :validates_associated,
19
- :validates_confirmation_of,
20
- :validates_exclusion_of,
21
- :validates_format_of,
22
- :validates_inclusion_of,
23
- :validates_length_of,
24
- :validates_numericality_of,
25
- :validates_presence_of,
26
- :validates_uniqueness_of,
27
- ].freeze
28
-
29
- @@reflected_validations = CORE_VALIDATONS.dup
30
- @@in_ignored_subvalidation = false
31
-
32
- mattr_accessor :reflected_validations,
33
- :in_ignored_subvalidation
34
-
35
- def included(base) # :nodoc:
36
- return if base.kind_of?(::ActiveRecordExtensions::ValidationReflection::ClassMethods)
37
- base.extend(ClassMethods)
38
- end
3
+ module ValidationReflection # :nodoc:
4
+
5
+ extend self
6
+
7
+ CORE_VALIDATONS = [
8
+ :validates_acceptance_of,
9
+ :validates_associated,
10
+ :validates_confirmation_of,
11
+ :validates_exclusion_of,
12
+ :validates_format_of,
13
+ :validates_inclusion_of,
14
+ :validates_length_of,
15
+ :validates_numericality_of,
16
+ :validates_presence_of,
17
+ :validates_uniqueness_of,
18
+ ].freeze
19
+
20
+ @@reflected_validations = CORE_VALIDATONS.dup
21
+
22
+ @@in_ignored_subvalidation = false
23
+
24
+ mattr_accessor :reflected_validations,
25
+ :in_ignored_subvalidation
26
+
27
+ def included(base) # :nodoc:
28
+ return if base.kind_of?(::ValidationReflection::ClassMethods)
29
+ base.extend(ClassMethods)
30
+ end
39
31
 
40
- # Load config/initializer on load, where ValidationReflection defaults
41
- # (such as which validations to reflect upon) cane be overridden/extended.
42
- #
43
- def load_config
44
- if ::File.file?(CONFIG_PATH)
45
- config = ::OpenStruct.new
46
- config.reflected_validations = @@reflected_validations
47
- silence_warnings do
48
- eval(::IO.read(CONFIG_PATH), binding, CONFIG_PATH)
49
- end
32
+ # Iterate through all validations and store/cache the info
33
+ # for later easy access.
34
+ #
35
+ def install(base)
36
+ @@reflected_validations.each do |validation_type|
37
+ next if base.respond_to?(:"#{validation_type}_with_reflection")
38
+ ignore_subvalidations = false
39
+
40
+ if validation_type.kind_of?(::Hash)
41
+ ignore_subvalidations = validation_type[:ignore_subvalidations]
42
+ validation_type = validation_type[:method]
50
43
  end
51
- end
52
-
53
- # Iterate through all validations and store/cache the info
54
- # for later easy access.
55
- #
56
- def install(base)
57
- @@reflected_validations.each do |validation_type|
58
- next if base.respond_to?(:"#{validation_type}_with_reflection")
59
- ignore_subvalidations = false
60
-
61
- if validation_type.kind_of?(::Hash)
62
- ignore_subvalidations = validation_type[:ignore_subvalidations]
63
- validation_type = validation_type[:method]
64
- end
65
-
66
- base.class_eval %{
67
- class << self
68
- def #{validation_type}_with_reflection(*attr_names)
69
- ignoring_subvalidations(#{ignore_subvalidations}) do
70
- #{validation_type}_without_reflection(*attr_names)
71
- remember_validation_metadata(:#{validation_type}, *attr_names)
72
- end
44
+
45
+ base.class_eval %{
46
+ class << self
47
+ def #{validation_type}_with_reflection(*attr_names)
48
+ ignoring_subvalidations(#{ignore_subvalidations}) do
49
+ #{validation_type}_without_reflection(*attr_names)
50
+ remember_validation_metadata(:#{validation_type}, *attr_names)
73
51
  end
74
- alias_method_chain :#{validation_type}, :reflection
75
52
  end
76
- }, __FILE__, __LINE__
77
- end
53
+ alias_method_chain :#{validation_type}, :reflection
54
+ end
55
+ }, __FILE__, __LINE__
78
56
  end
57
+ end
58
+ alias :reload :install
79
59
 
80
- module ClassMethods
60
+ module ClassMethods
81
61
 
82
- include ::ActiveRecordExtensions::ValidationReflection
62
+ include ::ValidationReflection
83
63
 
84
- # Returns an array of MacroReflection objects for all validations in the class
85
- def reflect_on_all_validations
86
- self.read_inheritable_attribute(:validations) || []
87
- end
64
+ # Returns an array of MacroReflection objects for all validations in the class
65
+ def reflect_on_all_validations
66
+ self.read_inheritable_attribute(:reflected_validations) || []
67
+ end
88
68
 
89
- # Returns an array of MacroReflection objects for all validations defined for the field +attr_name+.
90
- def reflect_on_validations_for(attr_name)
91
- self.reflect_on_all_validations.select do |reflection|
92
- reflection.name == attr_name.to_sym
93
- end
69
+ # Returns an array of MacroReflection objects for all validations defined for the field +attr_name+.
70
+ def reflect_on_validations_for(attr_name)
71
+ self.reflect_on_all_validations.select do |reflection|
72
+ reflection.name == attr_name.to_sym
94
73
  end
74
+ end
95
75
 
96
- private
76
+ private
97
77
 
98
- # Store validation info for easy and fast access.
99
- #
100
- def remember_validation_metadata(validation_type, *attr_names)
101
- configuration = attr_names.last.is_a?(::Hash) ? attr_names.pop : {}
102
- attr_names.flatten.each do |attr_name|
103
- self.write_inheritable_array :validations,
104
- [::ActiveRecord::Reflection::MacroReflection.new(validation_type, attr_name.to_sym, configuration, self)]
105
- end
78
+ # Store validation info for easy and fast access.
79
+ #
80
+ def remember_validation_metadata(validation_type, *attr_names)
81
+ configuration = attr_names.last.is_a?(::Hash) ? attr_names.pop : {}
82
+ attr_names.flatten.each do |attr_name|
83
+ self.write_inheritable_array :reflected_validations,
84
+ [::ActiveRecord::Reflection::MacroReflection.new(validation_type, attr_name.to_sym, configuration, self)]
106
85
  end
86
+ end
107
87
 
108
- def ignoring_subvalidations(ignore)
109
- save_ignore = self.in_ignored_subvalidation
110
- unless self.in_ignored_subvalidation
111
- self.in_ignored_subvalidation = ignore
112
- yield
113
- end
114
- ensure
115
- self.in_ignored_subvalidation = save_ignore
88
+ def ignoring_subvalidations(ignore)
89
+ save_ignore = self.in_ignored_subvalidation
90
+ unless self.in_ignored_subvalidation
91
+ self.in_ignored_subvalidation = ignore
92
+ yield
116
93
  end
94
+ ensure
95
+ self.in_ignored_subvalidation = save_ignore
96
+ end
117
97
 
118
- end
119
98
  end
120
99
  end
121
100
 
122
- ActiveRecord::Base.class_eval do
123
- include ::ActiveRecordExtensions::ValidationReflection
124
- ::ActiveRecordExtensions::ValidationReflection.load_config
125
- ::ActiveRecordExtensions::ValidationReflection.install(self)
101
+ ActiveSupport.on_load(:active_record) do
102
+ include ValidationReflection
103
+ ::ValidationReflection.install(self)
126
104
  end
@@ -17,13 +17,13 @@ end
17
17
  require 'validation_reflection'
18
18
 
19
19
  ActiveRecord::Base.class_eval do
20
- include ::ActiveRecordExtensions::ValidationReflection
21
- ::ActiveRecordExtensions::ValidationReflection.reflected_validations << :validates_something_weird
22
- ::ActiveRecordExtensions::ValidationReflection.reflected_validations << {
20
+ include ValidationReflection
21
+ ::ValidationReflection.reflected_validations << :validates_something_weird
22
+ ::ValidationReflection.reflected_validations << {
23
23
  :method => :validates_something_selfcontained,
24
24
  :ignore_subvalidations => true
25
25
  }
26
- ::ActiveRecordExtensions::ValidationReflection.install(self)
26
+ ::ValidationReflection.install(self)
27
27
  end
28
28
 
29
29
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{validation_reflection}
8
- s.version = "0.3.8"
8
+ s.version = "1.0.0.beta4"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christopher Redinger"]
12
- s.date = %q{2010-07-30}
12
+ s.date = %q{2010-06-12}
13
13
  s.description = %q{Adds reflective access to validations}
14
14
  s.email = %q{redinger@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.homepage = %q{http://github.com/redinger/validation_reflection}
32
32
  s.rdoc_options = ["--charset=UTF-8"]
33
33
  s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.6}
34
+ s.rubygems_version = %q{1.3.7}
35
35
  s.summary = %q{Adds reflective access to validations}
36
36
  s.test_files = [
37
37
  "test/test_helper.rb",
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
43
  s.specification_version = 3
44
44
 
45
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
46
  else
47
47
  end
48
48
  else
metadata CHANGED
@@ -1,12 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validation_reflection
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: -1512032865
5
+ prerelease: true
5
6
  segments:
7
+ - 1
6
8
  - 0
7
- - 3
8
- - 8
9
- version: 0.3.8
9
+ - 0
10
+ - beta4
11
+ version: 1.0.0.beta4
10
12
  platform: ruby
11
13
  authors:
12
14
  - Christopher Redinger
@@ -14,7 +16,7 @@ autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2010-07-30 00:00:00 -04:00
19
+ date: 2010-06-12 00:00:00 -04:00
18
20
  default_executable:
19
21
  dependencies: []
20
22
 
@@ -48,23 +50,29 @@ rdoc_options:
48
50
  require_paths:
49
51
  - lib
50
52
  required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
51
54
  requirements:
52
55
  - - ">="
53
56
  - !ruby/object:Gem::Version
57
+ hash: 3
54
58
  segments:
55
59
  - 0
56
60
  version: "0"
57
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
58
63
  requirements:
59
- - - ">="
64
+ - - ">"
60
65
  - !ruby/object:Gem::Version
66
+ hash: 25
61
67
  segments:
62
- - 0
63
- version: "0"
68
+ - 1
69
+ - 3
70
+ - 1
71
+ version: 1.3.1
64
72
  requirements: []
65
73
 
66
74
  rubyforge_project:
67
- rubygems_version: 1.3.6
75
+ rubygems_version: 1.3.7
68
76
  signing_key:
69
77
  specification_version: 3
70
78
  summary: Adds reflective access to validations