simple_validation 0.1.6 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YmJkZGM2N2M1MzI2OTA1YzNkYTEyNjlkYTg2YTU3OTg4ZTNkMTM1NQ==
5
- data.tar.gz: !binary |-
6
- YzQwOTJmZDZlMDZlMDMwOTZkNWRmZmFlNmI1MTM2NTY2YjFmNjIyZg==
2
+ SHA1:
3
+ metadata.gz: 6b7c206d961ee6ebca1d4a3a79b0af5173ca6208
4
+ data.tar.gz: c80fcd3c7df138cea081bd3fe6e4bb8f01251230
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- M2QzMzU5NDE0ODc1NGNkYzNmNDkyZWI1YTNiZDBhMzUxMTNiYmZjNGUyNTQ3
10
- MjViZTk3MTAyNzRmNTI3NWZjYTIzMjZlMzNmNDc3NDQ2Y2Q5MWZjNmI3NzNh
11
- NTM3MGEyM2RhOWIwNWRiM2IwM2E4Yzc3YThhZjIwODUxNjc3YWY=
12
- data.tar.gz: !binary |-
13
- NTMwMmMzYTAyZjAwMjg0OTNjNjE0MDFlNTczMmNjYWUxNDZlZTZhMDAxOWRl
14
- M2NiMTcwMGM5MjgxZjQzNmVlMDc3MjM4NzgwNmZiZjlkMzQ4ZDQ5YjMzODFh
15
- ZWQ3NzA3YzBhMTMwNDEwYzM5MWJiMGE0MTAwNTdkMDZhYjE5NzM=
6
+ metadata.gz: 3536a5744450d61d8ebd18884dc6113391c1e9c9d23648a5d2e74a9c28a8f906243db933a335dafd1eb72eed77e6f629aafc9e3c81e86c7a6cc9d245228b2c81
7
+ data.tar.gz: e48850cb854f178cdebb18e7a7c328d1b1c9a8cbd799063dd4686abab15ea96928101794c692e46244e4378a82afbb082a372af97c4a01f61a661a42e37cb0bf
@@ -1,3 +1,9 @@
1
+ v0.2.1
2
+ ------
3
+
4
+ * Drop support for ruby 1.8
5
+ * Style - pass rubocop style checks
6
+
1
7
  v0.1.6
2
8
  ------
3
9
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2013 Chirantan Mitra
1
+ Copyright (c) 2012-2015 Chirantan Mitra
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  [![Build Status](https://secure.travis-ci.org/chiku/simple_validation.png?branch=master)](https://travis-ci.org/chiku/simple_validation)
2
+ [![Build Status](https://drone.io/github.com/chiku/simple_validation/status.png)](https://drone.io/github.com/chiku/simple_validation/latest)
3
+ [![Gem Version](https://badge.fury.io/rb/simple_validation.svg)](http://badge.fury.io/rb/simple_validation)
2
4
  [![Code Climate](https://codeclimate.com/github/chiku/simple_validation.png)](https://codeclimate.com/github/chiku/simple_validation)
5
+ [![Coverage Status](https://coveralls.io/repos/chiku/simple_validation/badge.png?branch=master)](https://coveralls.io/r/chiku/simple_validation?branch=master)
3
6
 
4
7
  Overview
5
8
  --------
@@ -9,7 +12,8 @@ This is very simple gem to allow custom validations in a ruby object. You are su
9
12
  Dependencies
10
13
  ------------
11
14
 
12
- These are no runtime dependencies for this gem. You need minitest to run the tests for this gem.
15
+ There are no runtime dependencies for this gem. This gem runs with ruby 1.9+ or compatible versions. Ruby 1.8 isn't supported.
16
+ Please use version 0.1.6 og simple_validation if you wish to use ruby 1.8.
13
17
 
14
18
  Installation
15
19
  ------------
@@ -79,7 +83,9 @@ another_invalid_number.value # 17
79
83
  Running tests
80
84
  -------------
81
85
 
82
- Clone the repository and run `rake` from the root directory.
86
+ 1. Clone the repository.
87
+ 2. run `bundle` from the root directory.
88
+ 3. run `rake` from the root directory.
83
89
 
84
90
  Contributing
85
91
  ------------
@@ -1,7 +1,7 @@
1
1
  # simple_validation.rb
2
2
  #
3
3
  # Created by Chirantan Mitra on 2012-11-20
4
- # Copyright 2012-2013. All rights reserved
4
+ # Copyright 2012-2015. All rights reserved
5
5
  #
6
6
  # See LICENSE for license
7
7
  #
@@ -48,17 +48,18 @@
48
48
  # invalid_number.errors # ["-1 is negative", "12 is greater than 9"]
49
49
  # invalid_number.value # 11
50
50
 
51
- module SimpleValidation
51
+ module SimpleValidation # :nodoc:
52
52
  def self.included(base) # :nodoc:
53
53
  base.class_eval do
54
54
  base.extend SimpleValidation::ClassMethods
55
55
  end
56
56
  end
57
57
 
58
- module ClassMethods
58
+ module ClassMethods # :nodoc:
59
59
  # Add a validation method
60
60
  # The object to validate should be able to invoke the method supplied
61
- # You can pass a list of conditions that the object must satisfy for the validations to run
61
+ # You can pass a list of conditions that the object must satisfy for
62
+ # the validations to run
62
63
  #
63
64
  # Example:
64
65
  # class AlienNumber
@@ -79,11 +80,10 @@ module SimpleValidation
79
80
 
80
81
  # Run all validations associated with the object
81
82
  def validate # :nodoc:
82
- unless @validated ||= false
83
- @validated = true
84
- self.class.validation_methods.each do |method_name, conditions|
85
- send method_name if conditions.all? { |condition| send condition }
86
- end
83
+ return if @validated ||= false
84
+ @validated = true
85
+ self.class.validation_methods.each do |method_name, conditions|
86
+ send method_name if conditions.all? { |condition| send condition }
87
87
  end
88
88
  end
89
89
 
@@ -95,7 +95,7 @@ module SimpleValidation
95
95
 
96
96
  # Runs all validations and returns _true_ if the object is invalid
97
97
  def invalid?
98
- not valid?
98
+ !valid?
99
99
  end
100
100
 
101
101
  # Adds an error to the errors collection
@@ -1,10 +1,10 @@
1
1
  # version.rb
2
2
  #
3
3
  # Created by Chirantan Mitra on 2012-11-20
4
- # Copyright 2012-2013. All rights reserved
4
+ # Copyright 2012-2015. All rights reserved
5
5
  #
6
6
  # See LICENSE for license
7
7
 
8
- module SimpleValidation
9
- VERSION = "0.1.6"
8
+ module SimpleValidation # :nodoc:
9
+ VERSION = '0.2.1'
10
10
  end
@@ -1,13 +1,13 @@
1
1
  # simple_validation_spec.rb
2
2
  #
3
3
  # Created by Chirantan Mitra on 2012-11-20
4
- # Copyright 2012-2013. All rights reserved
4
+ # Copyright 2012-2015. All rights reserved
5
5
  #
6
6
  # See LICENSE for license
7
7
 
8
- require File.expand_path("spec_helper", File.dirname(__FILE__))
8
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
9
9
 
10
- require File.expand_path("../lib/simple_validation", File.dirname(__FILE__))
10
+ require File.expand_path('../lib/simple_validation', File.dirname(__FILE__))
11
11
 
12
12
  class TestEntity
13
13
  include SimpleValidation
@@ -33,7 +33,7 @@ class TestEntityWithValidation
33
33
 
34
34
  def always_invalid
35
35
  @always_invalid_invoked_count += 1
36
- add_error "Always invalid"
36
+ add_error 'Always invalid'
37
37
  end
38
38
  end
39
39
 
@@ -44,9 +44,9 @@ class TestEntityWithConditionalValidation
44
44
  attr_reader :statement_two_invoked_count
45
45
  attr_reader :statement_three_invoked_count
46
46
 
47
- validate :statement_one, :if => [:condition_one?]
48
- validate :statement_two, :if => [:condition_two?]
49
- validate :statement_three, :if => [:condition_one?, :condition_two?]
47
+ validate :statement_one, if: [:always_true?]
48
+ validate :statement_two, if: [:always_false?]
49
+ validate :statement_three, if: [:always_true?, :always_false?]
50
50
 
51
51
  def initialize
52
52
  @statement_one_invoked_count = 0
@@ -66,170 +66,152 @@ class TestEntityWithConditionalValidation
66
66
  @statement_three_invoked_count += 1
67
67
  end
68
68
 
69
- def condition_one?
69
+ def always_true?
70
70
  true
71
71
  end
72
72
 
73
- def condition_two?
73
+ def always_false?
74
74
  false
75
75
  end
76
76
  end
77
77
 
78
- describe "A validatable entity" do
79
- describe "with an error" do
80
- before do
81
- @entity = TestEntity.new
82
- @entity.add_error("An error")
83
- end
78
+ describe 'A validatable entity' do
79
+ describe 'with an error' do
80
+ subject { TestEntity.new }
81
+ before { subject.add_error('An error') }
84
82
 
85
- it "is invalid" do
86
- @entity.invalid?.must_equal true
83
+ it 'is invalid' do
84
+ subject.invalid?.must_equal true
87
85
  end
88
86
 
89
- it "is not valid" do
90
- @entity.valid?.must_equal false
87
+ it 'is not valid' do
88
+ subject.valid?.must_equal false
91
89
  end
92
90
 
93
- it "exposes its errors" do
94
- @entity.errors.must_equal ["An error"]
91
+ it 'exposes its errors' do
92
+ subject.errors.must_equal ['An error']
95
93
  end
96
94
  end
97
95
 
98
- describe "whithout any errors" do
99
- before do
100
- @entity = TestEntity.new
101
- end
96
+ describe 'whithout any errors' do
97
+ subject { TestEntity.new }
102
98
 
103
- it "is not invalid" do
104
- @entity.invalid?.must_equal false
99
+ it 'is not invalid' do
100
+ subject.invalid?.must_equal false
105
101
  end
106
102
 
107
- it "is valid" do
108
- @entity.valid?.must_equal true
103
+ it 'is valid' do
104
+ subject.valid?.must_equal true
109
105
  end
110
106
 
111
- it "exposes its errors as an empty array" do
112
- @entity.errors.must_equal []
107
+ it 'exposes its errors as an empty array' do
108
+ subject.errors.must_equal []
113
109
  end
114
110
  end
115
111
 
116
- describe "with custom validation" do
117
- before do
118
- @entity = TestEntityWithValidation.new
119
- end
112
+ describe 'with custom validation' do
113
+ subject { TestEntityWithValidation.new }
120
114
 
121
- describe "#valid?" do
122
- before do
123
- @entity.valid?
124
- end
115
+ describe '#valid?' do
116
+ before { subject.valid? }
125
117
 
126
- it "invokes its validations" do
127
- @entity.always_valid_invoked_count.must_equal 1
128
- @entity.always_invalid_invoked_count.must_equal 1
118
+ it 'invokes its validations' do
119
+ subject.always_valid_invoked_count.must_equal 1
120
+ subject.always_invalid_invoked_count.must_equal 1
129
121
  end
130
122
 
131
- it "has errors added during validation" do
132
- @entity.errors.must_equal ["Always invalid"]
123
+ it 'has errors added during validation' do
124
+ subject.errors.must_equal ['Always invalid']
133
125
  end
134
126
 
135
- describe "on another #valid?" do
136
- before do
137
- @entity.valid?
138
- end
127
+ describe 'on another #valid?' do
128
+ before { subject.valid? }
139
129
 
140
130
  it "doesn't duplicate its errors" do
141
- @entity.errors.must_equal ["Always invalid"]
131
+ subject.errors.must_equal ['Always invalid']
142
132
  end
143
133
 
144
134
  it "doesn't re-run validation" do
145
- @entity.always_valid_invoked_count.must_equal 1
146
- @entity.always_invalid_invoked_count.must_equal 1
135
+ subject.always_valid_invoked_count.must_equal 1
136
+ subject.always_invalid_invoked_count.must_equal 1
147
137
  end
148
138
  end
149
139
  end
150
140
 
151
- describe "#errors" do
152
- before do
153
- @entity.errors
154
- end
141
+ describe '#errors' do
142
+ before { subject.errors }
155
143
 
156
- it "invokes its validations" do
157
- @entity.always_valid_invoked_count.must_equal 1
158
- @entity.always_invalid_invoked_count.must_equal 1
144
+ it 'invokes its validations' do
145
+ subject.always_valid_invoked_count.must_equal 1
146
+ subject.always_invalid_invoked_count.must_equal 1
159
147
  end
160
148
 
161
- it "has errors added during validation" do
162
- @entity.errors.must_equal ["Always invalid"]
149
+ it 'has errors added during validation' do
150
+ subject.errors.must_equal ['Always invalid']
163
151
  end
164
152
 
165
- describe "on another #error" do
166
- before do
167
- @entity.errors
168
- end
153
+ describe 'on another #error' do
154
+ before { subject.errors }
169
155
 
170
156
  it "doesn't duplicate its errors" do
171
- @entity.errors.must_equal ["Always invalid"]
157
+ subject.errors.must_equal ['Always invalid']
172
158
  end
173
159
 
174
160
  it "doesn't re-run validation" do
175
- @entity.always_valid_invoked_count.must_equal 1
176
- @entity.always_invalid_invoked_count.must_equal 1
161
+ subject.always_valid_invoked_count.must_equal 1
162
+ subject.always_invalid_invoked_count.must_equal 1
177
163
  end
178
164
  end
179
165
  end
180
166
  end
181
167
 
182
- describe "with conditional validation" do
183
- before do
184
- @entity = TestEntityWithConditionalValidation.new
185
- end
168
+ describe 'with conditional validation' do
169
+ subject { TestEntityWithConditionalValidation.new }
186
170
 
187
- describe "#valid?" do
188
- before do
189
- @entity.valid?
190
- end
171
+ describe '#valid?' do
172
+ before { subject.valid? }
191
173
 
192
- it "invokes its validations that passes all conditions" do
193
- @entity.statement_one_invoked_count.must_equal 1
174
+ it 'invokes its validations that passes all conditions' do
175
+ subject.statement_one_invoked_count.must_equal 1
194
176
  end
195
177
 
196
178
  it "doesn't invoke its validations that fail all conditions" do
197
- @entity.statement_two_invoked_count.must_equal 0
179
+ subject.statement_two_invoked_count.must_equal 0
198
180
  end
199
181
 
200
182
  it "doesn't invoke its validations that fail conditions partially" do
201
- @entity.statement_three_invoked_count.must_equal 0
183
+ subject.statement_three_invoked_count.must_equal 0
202
184
  end
203
185
  end
204
186
  end
205
187
 
206
- describe "with already existing errors" do
188
+ describe 'with already existing errors' do
189
+ subject { TestEntityWithValidation.new }
190
+
207
191
  it "doesn't lose its older errors on validation" do
208
- entity = TestEntityWithValidation.new
209
- entity.add_error("An error")
210
- entity.errors.sort.must_equal ["An error", "Always invalid"].sort
192
+ subject.add_error('An error')
193
+ subject.errors.sort.must_equal ['An error', 'Always invalid'].sort
211
194
  end
212
195
 
213
196
  it "doesn't duplicate errors" do
214
- entity = TestEntityWithValidation.new
215
- entity.add_error("An error")
216
- entity.add_error("An error")
217
- entity.errors.sort.must_equal ["Always invalid", "An error"].sort
197
+ subject.add_error('An error')
198
+ subject.add_error('An error')
199
+ subject.errors.sort.must_equal ['Always invalid', 'An error'].sort
218
200
  end
219
201
  end
220
202
 
221
- describe "#add_error" do
222
- it "can accept multiple errors" do
223
- entity = TestEntity.new
224
- entity.add_errors(["An error", "Another error"])
225
- entity.errors.sort.must_equal ["An error", "Another error"].sort
203
+ describe '#add_error' do
204
+ subject { TestEntity.new }
205
+
206
+ it 'can accept multiple errors' do
207
+ subject.add_errors(['An error', 'Another error'])
208
+ subject.errors.sort.must_equal ['An error', 'Another error'].sort
226
209
  end
227
210
 
228
211
  it "doesn't duplicate errors" do
229
- entity = TestEntity.new
230
- entity.add_errors(["An error", "Another error"])
231
- entity.add_errors(["An error", "Another error"])
232
- entity.errors.sort.must_equal ["An error", "Another error"].sort
212
+ subject.add_errors(['An error', 'Another error'])
213
+ subject.add_errors(['An error', 'Another error'])
214
+ subject.errors.sort.must_equal ['An error', 'Another error'].sort
233
215
  end
234
216
  end
235
217
  end
@@ -1,18 +1,23 @@
1
1
  # spec_helper.rb
2
2
  #
3
3
  # Created by Chirantan Mitra on 2012-11-20
4
- # Copyright 2012-2013. All rights reserved
4
+ # Copyright 2012-2015. All rights reserved
5
5
  #
6
6
  # See LICENSE for license
7
7
 
8
8
  begin
9
9
  require 'simplecov'
10
+ require 'coveralls'
11
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new [
12
+ SimpleCov::Formatter::HTMLFormatter,
13
+ Coveralls::SimpleCov::Formatter
14
+ ]
10
15
  SimpleCov.start do
11
- add_filter "/spec|test|vendor/"
16
+ add_filter '/spec|test|vendor/'
12
17
  end
13
18
  rescue LoadError
14
- puts "\nPlease install simplecov to generate coverage report!\n\n"
19
+ puts "\nPlease install simplecov & coveralls to generate coverage report!\n\n"
15
20
  end
16
21
 
17
- require "minitest/autorun"
18
- require "minitest/spec"
22
+ require 'minitest/autorun'
23
+ require 'minitest/spec'
metadata CHANGED
@@ -1,59 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chirantan Mitra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-10 00:00:00.000000000 Z
11
+ date: 2015-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: simplecov
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: ! 'A simple way to validate custom ruby objects using validation defined
56
- in the class.
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: 'Validate custom ruby objects using validation defined in the class
57
84
 
58
85
  '
59
86
  email:
@@ -62,11 +89,11 @@ executables: []
62
89
  extensions: []
63
90
  extra_rdoc_files: []
64
91
  files:
65
- - lib/simple_validation/version.rb
66
- - lib/simple_validation.rb
92
+ - CHANGELOG.md
67
93
  - LICENSE
68
94
  - README.md
69
- - CHANGELOG.md
95
+ - lib/simple_validation.rb
96
+ - lib/simple_validation/version.rb
70
97
  - spec/simple_validation_spec.rb
71
98
  - spec/spec_helper.rb
72
99
  homepage: https://github.com/chiku/simple_validation
@@ -79,17 +106,17 @@ require_paths:
79
106
  - lib
80
107
  required_ruby_version: !ruby/object:Gem::Requirement
81
108
  requirements:
82
- - - ! '>='
109
+ - - ">="
83
110
  - !ruby/object:Gem::Version
84
111
  version: '0'
85
112
  required_rubygems_version: !ruby/object:Gem::Requirement
86
113
  requirements:
87
- - - ! '>='
114
+ - - ">="
88
115
  - !ruby/object:Gem::Version
89
116
  version: '0'
90
117
  requirements: []
91
118
  rubyforge_project: simple_validation
92
- rubygems_version: 2.1.10
119
+ rubygems_version: 2.5.1
93
120
  signing_key:
94
121
  specification_version: 4
95
122
  summary: Validations for a ruby object