rails_legit 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e68fe7cabdf5878a6f9deaf9d0e7f0c2efb3e11e
4
- data.tar.gz: cd7bb79827297860febee58476ca90540573c883
3
+ metadata.gz: 1cb1c1c1a1f24385f836da4e7305f27d9075bc35
4
+ data.tar.gz: 8740159a9cc237ae6b0663d19d02c014136b8a13
5
5
  SHA512:
6
- metadata.gz: 2e4cb7d0d52ed1f427006ce9fc3f220777ef83fc772038a8d05aa3fe087453d31fcd3ec220a915c103bdcacb782694285fd708da0002846ff595bc9ebcb71c61
7
- data.tar.gz: 7e6fc9d98bde417a6911ca836ebd1b97f0098d969d1618f84fe63e0cd4b07080fe10e1ca4b3de3f92983523b848e428b77ccca086e92e8e3e32c139711f9e3f7
6
+ metadata.gz: 42eca1cf50db6a14d592b47003d4456057ff4a01a73ef95ee460ffc62a7ebf57f7a96cd4d63f9179a047f7cb9b691c84f38504d95190eb2eb65b13fe6efa3d41
7
+ data.tar.gz: e86301506150cabf4b2710e31d8245b2d1bbde6f9b0e91ac6d4e6d0fb32d50edcbff988799fb39be3365e8e9cbf5b3a9c6860aadc677991c6c6d39078c61beaa
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ gemfile:
7
+ - Gemfile
8
+ - gemfiles/Gemfile.am-3.2
9
+
10
+ script:
11
+ - bundle exec rspec spec
data/README.md CHANGED
@@ -106,11 +106,11 @@ You can pass in a method as a symbol, string or a `Date` object. By default, all
106
106
  `:current`, `:today`, `:now` are sent to the object under validation.
107
107
 
108
108
  ```ruby
109
- validates :from_date, date: { greater_than: :current } # Date.current is used
110
- validates :from_date, date: { greater_than: :today } # Date.current is used
111
- validates :from_date, date: { greater_than: :now } # Date.current is used
109
+ validates :from_date, date: { after: :current } # Date.current is used
110
+ validates :from_date, date: { after: :today } # Date.current is used
111
+ validates :from_date, date: { after: :now } # Date.current is used
112
112
 
113
- validates :from_date, date: { greater_than: :end_date } # <EventForm Object>.end_date is used
113
+ validates :from_date, date: { after: :end_date } # <EventForm Object>.end_date is used
114
114
  ```
115
115
 
116
116
  Finally,
@@ -120,8 +120,8 @@ class EventForm
120
120
  attr_accessor :to_date, :from_date
121
121
  include ActiveModel::Model
122
122
  include RailsLegit
123
- validates :from_date, date: { greater_than: :today }
124
- validates :to_date, date: { greater_than: :from_date }
123
+ validates :from_date, date: { after: :today }
124
+ validates :to_date, date: { after: :from_date }
125
125
  end
126
126
  ```
127
127
 
@@ -132,54 +132,57 @@ of another array -- a list of valid IDs, for example. The `VerifyArray`
132
132
  validator handles the three cases of `:in`, :not_in` and `:eq`. The
133
133
  abstract functionality is as follows:
134
134
 
135
- # The simplest case would be to verify if a record attribute is an
136
- # Array
137
- validates [1, 2], verify_array: true # => true
135
+ ```ruby
136
+ # The simplest case would be to verify if a record attribute is an
137
+ # Array
138
+ validates [1, 2], verify_array: true # => true
138
139
 
139
- # Or, you could specify options. Supported options are :in, :not_in,
140
- # :eq
140
+ # Or, you could specify options. Supported options are :in, :not_in,
141
+ # :eq
141
142
 
142
- validates [1, 2, 3], verify_array: { in: [1, 2, 3, 4] } # => true
143
- # Note: The :in and :not_in validators are not strict. That is, the
144
- # following will work as expected. This is similar to :eq in this
145
- # case
146
- validates [1, 2, 3], verify_array: { in: [1, 2, 3] } # => true
147
- validates [1, 2, 3], verify_array: { in: [1, 2] } # => false
143
+ validates [1, 2, 3], verify_array: { in: [1, 2, 3, 4] } # => true
144
+ # Note: The :in and :not_in validators are not strict. That is, the
145
+ # following will work as expected. This is similar to :eq in this
146
+ # case
147
+ validates [1, 2, 3], verify_array: { in: [1, 2, 3] } # => true
148
+ validates [1, 2, 3], verify_array: { in: [1, 2] } # => false
148
149
 
149
- # The ordering is not a factor
150
- validates [3, 2, 1], verify_array: { in: [1, 2, 3, 4] } # => true
150
+ # The ordering is not a factor
151
+ validates [3, 2, 1], verify_array: { in: [1, 2, 3, 4] } # => true
151
152
 
152
- validates [1, 2], verify_array: { not_in: [4, 5] } # => true
153
- validates [1, 2], verify_array: { not_in: [1, 5] } # => true
153
+ validates [1, 2], verify_array: { not_in: [4, 5] } # => true
154
+ validates [1, 2], verify_array: { not_in: [1, 5] } # => true
154
155
 
155
- # :eq is a strict validator which will result true only if the given
156
- # array contains the exact same elements (irrespective of order)
157
- # compared to the verification array.
156
+ # :eq is a strict validator which will result true only if the given
157
+ # array contains the exact same elements (irrespective of order)
158
+ # compared to the verification array.
158
159
 
159
- validates [1, 2], verify_array: { eq: [2, 1] } # => true
160
- validates [1, 2], verify_array: { eq: [3, 1] } # => false
160
+ validates [1, 2], verify_array: { eq: [2, 1] } # => true
161
+ validates [1, 2], verify_array: { eq: [3, 1] } # => false
162
+ ```
161
163
 
162
164
  Use this in validating your models like so:
163
165
 
164
- # Specify a Symbol which is a method defined on the model
165
- class EventInvitees < ActiveRecord::Base
166
- validates :invited_users, verify_array: { in: :valid_users_in_db }
167
-
168
- def valid_users_in_db
169
- User.all.pluck(:id).map(&:to_s)
170
- end
171
- end
166
+ ```ruby
167
+ # Specify a Symbol which is a method defined on the model
168
+ class EventInvitees < ActiveRecord::Base
169
+ validates :invited_users, verify_array: { in: :valid_users_in_db }
172
170
 
173
- # or, specify an Array
174
- class EventInvitees < ActiveRecord::Base
175
- validates :invited_users, verify_array: { in: [1, 25, 155] }
176
- end
171
+ def valid_users_in_db
172
+ User.all.pluck(:id).map(&:to_s)
173
+ end
174
+ end
177
175
 
178
- # or, specify a Proc that returns an array
179
- class EventInvitees < ActiveRecord::Base
180
- validates :invited_users, verify_array: { in: ->{ [1, 25, 155] } }
181
- end
176
+ # or, specify an Array
177
+ class EventInvitees < ActiveRecord::Base
178
+ validates :invited_users, verify_array: { in: [1, 25, 155] }
179
+ end
182
180
 
181
+ # or, specify a Proc that returns an array
182
+ class EventInvitees < ActiveRecord::Base
183
+ validates :invited_users, verify_array: { in: ->{ [1, 25, 155] } }
184
+ end
185
+ ```
183
186
 
184
187
  The only caveat here is that the verification item (symbol/proc) should
185
188
  return an Array.
@@ -188,38 +191,42 @@ return an Array.
188
191
 
189
192
  To validate a hash, you can do like so:
190
193
 
191
- # some_hash = { one: 1, two: 2, three: 3 }
192
- validates some_hash, verify_hash: { keys: [:one, :two, :three] } # => true
193
- validates some_hash, verify_hash: { values: [1, 2, 3] } # => true
194
+ ```ruby
195
+ # some_hash = { one: 1, two: 2, three: 3 }
196
+ validates some_hash, verify_hash: { keys: [:one, :two, :three] } # => true
197
+ validates some_hash, verify_hash: { values: [1, 2, 3] } # => true
198
+ ```
194
199
 
195
200
  The valid options are `:keys` and `:values`. You can pass in an Array or
196
201
  a Proc that evaluates to an array or a method that is defined inside the
197
202
  class.
198
203
 
199
- # You can use an Array as the option's value
204
+ ```ruby
205
+ # You can use an Array as the option's value
200
206
 
201
- class User < ActiveRecord::Base
202
- validates :settings, verify_hash: { keys: ['public_email', 'public_profile'] }
203
- end
207
+ class User < ActiveRecord::Base
208
+ validates :settings, verify_hash: { keys: ['public_email', 'public_profile'] }
209
+ end
204
210
 
205
- # You can use a Proc
211
+ # You can use a Proc
206
212
 
207
- class User < ActiveRecord::Base
208
- validates :settings, verify_hash: { keys: -> { ['public_email', 'public_profile'] } }
209
- end
213
+ class User < ActiveRecord::Base
214
+ validates :settings, verify_hash: { keys: -> { ['public_email', 'public_profile'] } }
215
+ end
210
216
 
211
- # Or, you can use a Symbol if a method with that name is defined
217
+ # Or, you can use a Symbol if a method with that name is defined
212
218
 
213
- class User < ActiveRecord::Base
214
- validates :settings, verify_hash: { keys: :accepted_settings }
219
+ class User < ActiveRecord::Base
220
+ validates :settings, verify_hash: { keys: :accepted_settings }
215
221
 
216
- # The method can be private or a visible one
217
- private
222
+ # The method can be private or a visible one
223
+ private
218
224
 
219
- def accepted_settings
220
- ['public_email', 'public_profile']
221
- end
222
- end
225
+ def accepted_settings
226
+ ['public_email', 'public_profile']
227
+ end
228
+ end
229
+ ```
223
230
 
224
231
  The keys or values are checked for existence and not for equality. In
225
232
  other words even if the hash in the first example in Hash section was `{
@@ -0,0 +1,6 @@
1
+ # -*- ruby -*-
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gemspec path: '..'
6
+ gem 'activemodel', "~> 3.2"
@@ -78,7 +78,7 @@ module RailsLegit
78
78
 
79
79
  def try_to_convert_to_date(arg)
80
80
  if arg.respond_to? :to_date
81
- arg.to_date
81
+ arg.to_date rescue false
82
82
  else
83
83
  begin
84
84
  Date.parse(arg.to_s)
@@ -1,3 +1,3 @@
1
1
  module RailsLegit
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
- spec.add_dependency "activemodel", "~> 4.0.0"
24
+ spec.add_dependency "activemodel", "> 3.0"
25
25
  end
@@ -1,4 +1,5 @@
1
1
  require "active_model"
2
+ require "active_support/core_ext/string/conversions"
2
3
 
3
4
  shared_examples "basic date validations" do
4
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_legit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kashyap
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-08 00:00:00.000000000 Z
11
+ date: 2014-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: activemodel
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - '>'
60
60
  - !ruby/object:Gem::Version
61
- version: 4.0.0
61
+ version: '3.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - '>'
67
67
  - !ruby/object:Gem::Version
68
- version: 4.0.0
68
+ version: '3.0'
69
69
  description: Provides a DSL for common validation formats like Date, Array, DateTime
70
70
  etc.
71
71
  email:
@@ -75,10 +75,12 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - .gitignore
78
+ - .travis.yml
78
79
  - Gemfile
79
80
  - LICENSE.txt
80
81
  - README.md
81
82
  - Rakefile
83
+ - gemfiles/Gemfile.am-3.2
82
84
  - lib/rails_legit.rb
83
85
  - lib/rails_legit/verify_array_validator.rb
84
86
  - lib/rails_legit/verify_date_validator.rb