formeze 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -285,9 +285,10 @@ class ExampleForm < Formeze::Form
285
285
  end
286
286
  ```
287
287
 
288
- The error for the email validation would use the `formeze.errors.invalid`
289
- I18n key, defaulting to "is invalid". The error message for the password
290
- confirmation validation would use the `formeze.errors.does_not_match` key.
288
+ The error for the email field validation would include the value of the
289
+ `formeze.errors.invalid` I18n key, defaulting to "is invalid" if the I18n
290
+ key does not exist. The error for the password_confirmation field validation
291
+ would include the value of the `formeze.errors.does_not_match` I18n key.
291
292
 
292
293
 
293
294
  Rails usage
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'formeze'
3
- s.version = '2.0.0'
3
+ s.version = '2.1.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
@@ -1,25 +1,11 @@
1
1
  require 'cgi'
2
2
 
3
3
  module Formeze
4
- class Label
5
- def initialize(name)
6
- @name = name
7
- end
8
-
9
- def to_s
10
- @name.to_s.tr('_', ' ').capitalize
11
- end
12
- end
13
-
14
4
  class Field
15
5
  attr_reader :name
16
6
 
17
7
  def initialize(name, options = {})
18
8
  @name, @options = name, options
19
-
20
- if options.has_key?(:word_limit)
21
- Kernel.warn '[formeze] :word_limit option is deprecated, please use custom validation instead'
22
- end
23
9
  end
24
10
 
25
11
  def validate(value, form)
@@ -57,7 +43,7 @@ module Formeze
57
43
  end
58
44
 
59
45
  def label
60
- @options.fetch(:label) { Formeze.translate(name, :scope => [:formeze, :labels], :default => Label.new(name)) }
46
+ @options.fetch(:label) { Formeze.translate(name, :scope => [:formeze, :labels], :default => Formeze.label(name)) }
61
47
  end
62
48
 
63
49
  def required?
@@ -73,21 +59,13 @@ module Formeze
73
59
  end
74
60
 
75
61
  def too_long?(value)
76
- too_many_characters?(value) || too_many_words?(value)
62
+ value.chars.count > @options.fetch(:maxlength) { 64 }
77
63
  end
78
64
 
79
65
  def too_short?(value)
80
66
  @options.has_key?(:minlength) && value.chars.count < @options.fetch(:minlength)
81
67
  end
82
68
 
83
- def too_many_characters?(value)
84
- value.chars.count > @options.fetch(:maxlength) { 64 }
85
- end
86
-
87
- def too_many_words?(value)
88
- @options.has_key?(:word_limit) && value.scan(/\w+/).length > @options[:word_limit]
89
- end
90
-
91
69
  def no_match?(value)
92
70
  @options.has_key?(:pattern) && value !~ @options[:pattern]
93
71
  end
@@ -164,12 +142,8 @@ module Formeze
164
142
  @options.has_key?(:when) ? form.instance_eval(&@options[:when]) : true
165
143
  end
166
144
 
167
- def value?(form)
168
- form.send(@field.name) =~ /\S/
169
- end
170
-
171
145
  def validate(form)
172
- if validates?(form) && value?(form)
146
+ if validates?(form) && !form.errors_on?(@field.name)
173
147
  return_value = if @block.arity == 1
174
148
  @block.call(form.send(@field.name))
175
149
  else
@@ -345,6 +319,10 @@ module Formeze
345
319
  end
346
320
  end
347
321
 
322
+ def self.label(field_name)
323
+ field_name.to_s.tr('_', ' ').capitalize
324
+ end
325
+
348
326
  def self.scrub_methods
349
327
  @scrub_methods ||= {
350
328
  :strip => :strip.to_proc,
@@ -269,23 +269,6 @@ describe 'FormWithMinLengthField after parsing input with too few characters' do
269
269
  end
270
270
  end
271
271
 
272
- class FormWithWordLimitedField < Formeze::Form
273
- field :title, :word_limit => 2
274
- end
275
-
276
- describe 'FormWithWordLimitedField after parsing input with too many words' do
277
- before do
278
- @form = FormWithWordLimitedField.new
279
- @form.parse('title=This+Title+Will+Be+Too+Long')
280
- end
281
-
282
- describe 'valid query method' do
283
- it 'returns false' do
284
- @form.valid?.must_equal(false)
285
- end
286
- end
287
- end
288
-
289
272
  class FormWithFieldThatMustMatchPattern < Formeze::Form
290
273
  field :number, :pattern => /\A\d+\z/
291
274
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formeze
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-10 00:00:00.000000000 Z
12
+ date: 2013-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -75,9 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 1.8.25
78
+ rubygems_version: 1.8.23
79
79
  signing_key:
80
80
  specification_version: 3
81
81
  summary: See description
82
82
  test_files: []
83
- has_rdoc: