validation_rules 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzVjNTIxODFjZDZkNTVjMWMwMzAyYmFiOTIxNGFmN2JhN2UyYmRmYQ==
5
+ data.tar.gz: !binary |-
6
+ OTQ2ZDJkYjE5OWJkNmE3MGY1YzZkZmEwOWJhMmViMmMwOGRkNzc0Zg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NDlmMmY0NWU2ZTk5MmZhMGYyNDE2Zjg3OTIwOWQyYzA4MzdlZTI0ZGZhNzFk
10
+ MTVlYmE2ZGFmZTNmNjMwM2FmMDA1ZTkyZDY0NzM3MjY4OGE3MzExNjcwNWUx
11
+ OTBjZTUzNDQwOWY1N2YxMTQ3M2YwNzY5ZWZhY2NlNTZiZDBhZDY=
12
+ data.tar.gz: !binary |-
13
+ ZGFiYzYxNDI2ZTYxNzNlMWJmMjE0MDMyMWU4ZjcwYmNlYmE1N2NkZWM2ZTQ1
14
+ ZDlhNGVjZDM0NGJlN2JkYThkOWIwMDE2MmQ1MzdkNTc1MzM3MmUwZDIzZjM4
15
+ YjZlZTZhZWJhNjc2MDUyNWEwYTQwNmZlZmE2NDAwZDg0ZGVjYzk=
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
1
  # validation_rules gem
2
2
 
3
- Documentation coming soon
3
+ A collection of commonly used Ruby validation rules
4
+
5
+ `gem "validation_rules", "~> 1.0.2"`
6
+
7
+ No documentationn yet, use http://rubydoc.info/gems/validation_rules/1.0.2/frames
@@ -126,4 +126,12 @@ module ValidationRules
126
126
  def self.range(value, min, max)
127
127
  value.to_f >= min.to_f and value.to_f <= max.to_f
128
128
  end
129
+
130
+ def self.bool(value)
131
+ !!value == value
132
+ end
133
+
134
+ def self.any_bool(value)
135
+ [true, false, 0, 1, "0", "1", "true", "false"].include?(value)
136
+ end
129
137
  end
@@ -1,3 +1,3 @@
1
1
  module ValidationRules
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.2'
3
3
  end
@@ -294,4 +294,67 @@ describe ValidationRules do
294
294
 
295
295
  ValidationRules.future_date('2010-10-25').should be_false
296
296
  end
297
+
298
+ subject do
299
+ ValidationRules
300
+ end
301
+
302
+ describe '.bool' do
303
+ it 'validates for boolean true' do
304
+ subject.bool(true).should be_true
305
+ end
306
+
307
+ it 'validates for boolean false' do
308
+ subject.bool(false).should be_true
309
+ end
310
+
311
+ it 'rejects non bool' do
312
+ subject.bool('true').should be_false
313
+ subject.bool('false').should be_false
314
+ subject.bool('1').should be_false
315
+ subject.bool('0').should be_false
316
+ subject.bool('abc').should be_false
317
+ subject.bool(5).should be_false
318
+ end
319
+ end
320
+
321
+ describe '.any_bool' do
322
+ it 'validates for boolean true' do
323
+ subject.any_bool(true).should be_true
324
+ end
325
+
326
+ it 'validates for any_boolean false' do
327
+ subject.any_bool(false).should be_true
328
+ end
329
+
330
+ it 'validates for string true' do
331
+ subject.any_bool('true').should be_true
332
+ end
333
+
334
+ it 'validates for string false' do
335
+ subject.any_bool('false').should be_true
336
+ end
337
+
338
+ it 'validates for int 1' do
339
+ subject.any_bool(1).should be_true
340
+ end
341
+
342
+ it 'validates for int 0' do
343
+ subject.any_bool(0).should be_true
344
+ end
345
+
346
+ it 'validates for string 1' do
347
+ subject.any_bool('1').should be_true
348
+ end
349
+
350
+ it 'validates for string 0' do
351
+ subject.any_bool('0').should be_true
352
+ end
353
+
354
+ it 'rejects non bool' do
355
+ subject.any_bool('5').should be_false
356
+ subject.any_bool('abc').should be_false
357
+ subject.any_bool(5).should be_false
358
+ end
359
+ end
297
360
  end
metadata CHANGED
@@ -1,47 +1,35 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: validation_rules
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Adam Gotterer
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-04-05 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: rspec
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 13
29
- segments:
30
- - 1
31
- - 2
32
- - 9
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
33
19
  version: 1.2.9
34
20
  type: :development
35
- version_requirements: *id001
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.9
36
27
  description: A collection of common validation rules
37
28
  email: agotterer+gem@gmail.com
38
29
  executables: []
39
-
40
30
  extensions: []
41
-
42
31
  extra_rdoc_files: []
43
-
44
- files:
32
+ files:
45
33
  - lib/validation_rules/validation_rules.rb
46
34
  - lib/validation_rules/version.rb
47
35
  - lib/validation_rules.rb
@@ -51,40 +39,27 @@ files:
51
39
  - spec/validation_rules_spec.rb
52
40
  homepage: https://github.com/adamgotterer/validation_rules
53
41
  licenses: []
54
-
42
+ metadata: {}
55
43
  post_install_message:
56
44
  rdoc_options: []
57
-
58
- require_paths:
45
+ require_paths:
59
46
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 55
66
- segments:
67
- - 1
68
- - 9
69
- - 2
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
70
51
  version: 1.9.2
71
- required_rubygems_version: !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 0
79
- version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
80
57
  requirements: []
81
-
82
58
  rubyforge_project:
83
- rubygems_version: 1.8.24
59
+ rubygems_version: 2.0.3
84
60
  signing_key:
85
- specification_version: 3
61
+ specification_version: 4
86
62
  summary: A collection of common validation rules
87
- test_files:
63
+ test_files:
88
64
  - spec/spec_helper.rb
89
65
  - spec/validation_rules_spec.rb
90
- has_rdoc: