midas-g_live_validator 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.0.4 2009-06-03
2
+
3
+ * Added the g_live_dynamic_validations view helper that works with dynamic validations gem
4
+
5
+
1
6
  == 1.0.4 2009-04-03
2
7
 
3
8
  * Added support for InacvtiveRecord (http://github.com/midas/inactive_record/tree/master) validations
data/Manifest.txt CHANGED
@@ -6,6 +6,7 @@ Rakefile
6
6
  g_live_validator.gemspec
7
7
  lib/g_live_validator.rb
8
8
  lib/g_live_validator/active_record_extensions.rb
9
+ lib/g_live_validator/validation_definition.rb
9
10
  lib/g_live_validator/view_helpers.rb
10
11
  live_validator.gemspec
11
12
  rails_generators/live_validator_assets/live_validator_assets_generator.rb
data/README.rdoc CHANGED
@@ -29,19 +29,19 @@ valdiations.
29
29
 
30
30
  == INSTALL:
31
31
 
32
- sudo gem install midas-live_validator
33
-
34
-
35
- == USE:
32
+ sudo gem install midas-g_live_validator
36
33
 
37
34
  Add gem requirement to your environment.rb file:
38
35
 
39
- config.gem 'midas-live_validator', :version => '1.0.3', :lib => 'live_validator', :source => 'http://gems.github.com'
36
+ config.gem 'midas-g_live_validator', :version => '1.0.4', :lib => 'g_live_validator', :source => 'http://gems.github.com'
40
37
 
41
- Generate the assets for live validator:
38
+ Generate:
42
39
 
43
40
  script/generate live_validator_assets
44
41
 
42
+
43
+ == USE:
44
+
45
45
  Make a call to the view_helper within a form:
46
46
 
47
47
  <%= g_live_validator f %> # where f is the form variable passed into the form_for block
@@ -58,6 +58,7 @@ symbol or an array of string or sybmols.
58
58
  * Guilded >= 0.1.3 (http://github.com/midas/guilded/tree/master)
59
59
  * Rails >= 2.0
60
60
 
61
+
61
62
  == LICENSE:
62
63
 
63
64
  (The MIT License)
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{g_live_validator}
5
- s.version = "1.0.4"
5
+ s.version = "1.0.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["C. Jason Harrelson (midas)"]
9
- s.date = %q{2009-04-03}
9
+ s.date = %q{2009-06-03}
10
10
  s.description = %q{Live validator is a Rails Guilded (http://github.com/midas/guilded/tree/master) component that will reflect ActiveRecord validations and use them to live validate forms. Live validator uses the Live Validation (http://www.livevalidation.com) JavaScript library to accomplish this task. It also uses an ActiveRecord extension authored by Michael Schuerig to mre easily reflect on the ActiveRecord valdiations.}
11
11
  s.email = ["jason@lookforwardenterprises.com"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
13
- s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "g_live_validator.gemspec", "lib/g_live_validator.rb", "lib/g_live_validator/active_record_extensions.rb", "lib/g_live_validator/view_helpers.rb", "live_validator.gemspec", "rails_generators/live_validator_assets/live_validator_assets_generator.rb", "rails_generators/live_validator_assets/templates/default.css", "rails_generators/live_validator_assets/templates/guilded.live_validator.js", "rails_generators/live_validator_assets/templates/guilded.live_validator.min.js", "rails_generators/live_validator_assets/templates/livevalidation-1.3.js", "rails_generators/live_validator_assets/templates/livevalidation-1.3.min.js", "script/console", "script/destroy", "script/generate", "spec/live_validator_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
13
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "g_live_validator.gemspec", "lib/g_live_validator.rb", "lib/g_live_validator/active_record_extensions.rb", "lib/g_live_validator/validation_definition.rb", "lib/g_live_validator/view_helpers.rb", "live_validator.gemspec", "rails_generators/live_validator_assets/live_validator_assets_generator.rb", "rails_generators/live_validator_assets/templates/default.css", "rails_generators/live_validator_assets/templates/guilded.live_validator.js", "rails_generators/live_validator_assets/templates/guilded.live_validator.min.js", "rails_generators/live_validator_assets/templates/livevalidation-1.3.js", "rails_generators/live_validator_assets/templates/livevalidation-1.3.min.js", "script/console", "script/destroy", "script/generate", "spec/live_validator_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/midas/live_validator/tree/master}
16
16
  s.post_install_message = %q{PostInstall.txt}
@@ -25,18 +25,18 @@ Gem::Specification.new do |s|
25
25
  s.specification_version = 2
26
26
 
27
27
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
28
+ s.add_development_dependency(%q<newgem>, [">= 1.3.0"])
29
29
  s.add_development_dependency(%q<rails>, [">= 2.2.0"])
30
30
  s.add_development_dependency(%q<midas-guilded>, [">= 0.1.4"])
31
31
  s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
32
32
  else
33
- s.add_dependency(%q<newgem>, [">= 1.2.3"])
33
+ s.add_dependency(%q<newgem>, [">= 1.3.0"])
34
34
  s.add_dependency(%q<rails>, [">= 2.2.0"])
35
35
  s.add_dependency(%q<midas-guilded>, [">= 0.1.4"])
36
36
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
37
37
  end
38
38
  else
39
- s.add_dependency(%q<newgem>, [">= 1.2.3"])
39
+ s.add_dependency(%q<newgem>, [">= 1.3.0"])
40
40
  s.add_dependency(%q<rails>, [">= 2.2.0"])
41
41
  s.add_dependency(%q<midas-guilded>, [">= 0.1.4"])
42
42
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
@@ -0,0 +1,21 @@
1
+ module GLiveValidator
2
+
3
+ class ValidationDefinition
4
+ attr_accessor :active_record, :macro, :name, :options
5
+
6
+ def initialize( validation )
7
+ if validation.is_a?(ActiveRecord::Reflection::MacroReflection )
8
+ self.active_record = validation.active_record
9
+ self.macro = validation.macro
10
+ self.name = validation.name
11
+ self.options = validation.options
12
+ elsif validation.is_a?( ValidationRule )
13
+ self.active_record = validation.entity_type.constantize
14
+ self.macro = "validates_#{validation.validation}_of"
15
+ self.name = validation.attribute
16
+ self.options = YAML.load( validation.description ) unless validation.description.nil?
17
+ end
18
+ end
19
+ end
20
+
21
+ end
@@ -51,38 +51,24 @@ module GLiveValidator
51
51
  #options.merge! :human_names => form.object
52
52
 
53
53
  validations = g_map_validations( klass.reflect_on_all_validations )
54
+ validations = apply_options( form, validations, options )
54
55
 
55
- # Remove any foreign keys as they will not be present on the form
56
- validations.reject! { |field, validation| field.include?( "_id" ) }
56
+ options.merge! :validations => validations
57
+ Guilded::Guilder.instance.add( :live_validator, options, [ 'livevalidation-1.3.min.js' ] )
58
+ return ""
59
+ end
60
+
61
+ def g_live_dynamic_validator( form, validation_rules, *args )
62
+ options = args.extract_options!
63
+ klass = form.object.class
64
+ class_name = klass.to_s.downcase
65
+ options.merge! :id => "live-validator-#{class_name}"
66
+ ar_obj_name = form.object.class.to_s.underscore
57
67
 
58
- # Remove any excepts, if necessary
59
- if options[:except]
60
- if options[:except].is_a?( Array )
61
- excepts = options[:except]
62
- elsif options[:except].is_a?( String ) || options[:except].is_a?( Symbol )
63
- excepts = Array.new << options[:except]
64
- else
65
- throw "'Except' option must be a string symbol or arry of strings or symbols"
66
- end
67
-
68
- # Add the AR object name to the field name, as Rails does this on forms
69
- excepts.map! { |except| "#{ar_obj_name}_#{except.to_s}" }
70
-
71
- excepts.each do |except|
72
- validations.reject! { |field, validation| field == except }
73
- end
74
- end
68
+ validation_defs = validation_rules.map { |validation_rule| ValidationDefinition.new( validation_rule ) }
75
69
 
76
- # Handle nested form namings, if necessary
77
- if form.object.class.to_s.underscore != form.object_name
78
- #field_precursor = form.object_name.gsub( /\[/, '_' ).gsub( /\]/, '_' )
79
- field_precursor = form.object_name[0...form.object_name.index( "[" )] + '_'
80
- nested_validations = Hash.new
81
- validations.each do |key, value|
82
- nested_validations[ "#{field_precursor}#{key}".to_sym ] = value
83
- end
84
- validations = nested_validations
85
- end
70
+ validations = g_map_validations( validation_defs )
71
+ validations = apply_options( form, validations, options )
86
72
 
87
73
  options.merge! :validations => validations
88
74
  Guilded::Guilder.instance.add( :live_validator, options, [ 'livevalidation-1.3.min.js' ] )
@@ -177,5 +163,40 @@ module GLiveValidator
177
163
  return validations
178
164
  end
179
165
 
166
+ def apply_options( form, validations, options )
167
+ # Remove any foreign keys as they will not be present on the form
168
+ validations.reject! { |field, validation| field.include?( "_id" ) }
169
+
170
+ # Remove any excepts, if necessary
171
+ if options[:except]
172
+ if options[:except].is_a?( Array )
173
+ excepts = options[:except]
174
+ elsif options[:except].is_a?( String ) || options[:except].is_a?( Symbol )
175
+ excepts = Array.new << options[:except]
176
+ else
177
+ throw "'Except' option must be a string symbol or arry of strings or symbols"
178
+ end
179
+
180
+ # Add the AR object name to the field name, as Rails does this on forms
181
+ excepts.map! { |except| "#{ar_obj_name}_#{except.to_s}" }
182
+
183
+ excepts.each do |except|
184
+ validations.reject! { |field, validation| field == except }
185
+ end
186
+ end
187
+
188
+ # Handle nested form namings, if necessary
189
+ if form.object.class.to_s.underscore != form.object_name
190
+ #field_precursor = form.object_name.gsub( /\[/, '_' ).gsub( /\]/, '_' )
191
+ field_precursor = form.object_name[0...form.object_name.index( "[" )] + '_'
192
+ nested_validations = Hash.new
193
+ validations.each do |key, value|
194
+ nested_validations[ "#{field_precursor}#{key}".to_sym ] = value
195
+ end
196
+ validations = nested_validations
197
+ end
198
+
199
+ validations
200
+ end
180
201
  end
181
202
  end
@@ -2,10 +2,11 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  require 'g_live_validator/view_helpers'
5
+ require 'g_live_validator/validation_definition'
5
6
  require 'g_live_validator/active_record_extensions'
6
7
 
7
8
  module GLiveValidator
8
- VERSION = '1.0.4'
9
+ VERSION = '1.0.5'
9
10
  end
10
11
 
11
12
  if defined?( ActiveRecord::Base )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midas-g_live_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - C. Jason Harrelson (midas)
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-03 00:00:00 -07:00
12
+ date: 2009-06-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.2.3
23
+ version: 1.3.0
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
@@ -73,6 +73,7 @@ files:
73
73
  - g_live_validator.gemspec
74
74
  - lib/g_live_validator.rb
75
75
  - lib/g_live_validator/active_record_extensions.rb
76
+ - lib/g_live_validator/validation_definition.rb
76
77
  - lib/g_live_validator/view_helpers.rb
77
78
  - live_validator.gemspec
78
79
  - rails_generators/live_validator_assets/live_validator_assets_generator.rb