active_validation 4.0.5 → 4.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ff5f0f171d58eb1aef241aef85f4d4e201a2b0f
4
- data.tar.gz: 74f0b459cbbee160ad936388ae51033afa1f7b9f
3
+ metadata.gz: a7d8a4c60d44f74ace63f5416af7c92ceca82844
4
+ data.tar.gz: de8ff337595b71667495cd067072ccaa0ca9d0ac
5
5
  SHA512:
6
- metadata.gz: 8ed76c3d3a02038791088b23129dfdef94ec95c5a5dcab7497b7e25282c84549bc81180d8f794fbf8783e3e52bbd718ac91e92245d2c2f65145224831e0c95fd
7
- data.tar.gz: 2a28bc6f07d48db9e69fe0c87592493ddb6ee44d33cfac822b5ca395ef796dbc2a292d3ee8abc2226e54529b6968899a5dd8d37b456518d67bc0e0b03052ed0d
6
+ metadata.gz: f10b556bdadc2f3df830a85e5e0cd7aca7939ff0b32575f314fc22c6ffc049fae0b0317e159735f2b9ad3f4b341a4f7fcb588d84ece4de468598b5a4b52b7e76
7
+ data.tar.gz: 446a216633b65e6ce31a49d124d9a1b5b59e801263cb3d60eb53002edf9ab97d440934a87ac3fcd2930fb94330996d3c53ea61d6cb6fb8f328a75e7a2ef59034
data/README.md CHANGED
@@ -50,6 +50,7 @@ Or install it yourself as:
50
50
  * [SEDOL](#sedolvalidator)
51
51
  * [Slug](#slugvalidator)
52
52
  * [SSN](#ssnvalidator)
53
+ * [Time Zone](#timezonevalidator)
53
54
  * [Tracking Number](#trackingnumbervalidator)
54
55
  * [Type](#typevalidator)
55
56
  * [URL](#urlvalidator)
@@ -918,6 +919,40 @@ describe User do
918
919
  end
919
920
  ```
920
921
 
922
+ ## TimeZoneValidator
923
+
924
+ **Ex:** 'America/New_York' or 'London'
925
+
926
+ **Rules:**
927
+ * Any valid time zone
928
+
929
+ With an ActiveRecord model:
930
+
931
+ ```ruby
932
+ class User < ActiveRecord::Base
933
+ attr_accessor :time_zone, :name
934
+ validates :time_zone, time_zone: true
935
+ ```
936
+
937
+ Or any ruby class:
938
+
939
+ ```ruby
940
+ class User
941
+ include ActiveModel::Validations
942
+ attr_accessor :time_zone, :name
943
+ validates :time_zone, time_zone: true
944
+ end
945
+ ```
946
+
947
+ RSpec matcher is also available for your convenience:
948
+
949
+ ```ruby
950
+ describe User do
951
+ it { should ensure_valid_type_format_of(:time_zone) }
952
+ it { should_not ensure_valid_type_format_of(:name) }
953
+ end
954
+ ```
955
+
921
956
  ## TrackingNumberValidator
922
957
 
923
958
  **Ex:** 1Z8V92A70367203024
@@ -27,6 +27,7 @@ en:
27
27
  sedol: 'is not in valid SEDOL format'
28
28
  slug: 'is not in valid slug format'
29
29
  ssn: 'is not in valid social security number format'
30
+ time_zone: 'is not a valid time zone'
30
31
  tracking_number: 'is not in valid tracking number format'
31
32
  type: 'is not a valid type'
32
33
  url: 'is not in valid URL format'
@@ -99,6 +100,9 @@ en:
99
100
  ensure_valid_ssn_format_of:
100
101
  failure_message_for_should: '%{model} should ensure valid SSN format of attribute %{attr}'
101
102
  failure_message_for_should_not: '%{model} should not ensure valid SSN format of attribute %{attr}'
103
+ ensure_valid_time_zone_format_of:
104
+ failure_message_for_should: '%{model} should ensure valid time zone of attribute %{attr}'
105
+ failure_message_for_should_not: '%{model} should not ensure valid time zone of attribute %{attr}'
102
106
  ensure_valid_tracking_number_format_of:
103
107
  failure_message_for_should: '%{model} should ensure valid tracking number format of attribute %{attr}'
104
108
  failure_message_for_should_not: '%{model} should not ensure valid tracking number format of attribute %{attr}'
@@ -0,0 +1,24 @@
1
+ class TimeZoneValidator < ActiveModel::EachValidator
2
+
3
+ def validate_each(record, attribute, value)
4
+ return if valid?(value)
5
+ record.errors[attribute] <<
6
+ (options[:message] || I18n.t('active_validation.errors.messages.time_zone'))
7
+ end
8
+
9
+ private
10
+
11
+ def valid_time_zone?(value)
12
+ ActiveSupport::TimeZone[value].present?
13
+ end
14
+
15
+ def valid_length?(value)
16
+ value.present?
17
+ end
18
+
19
+ def valid?(value)
20
+ valid_length?(value) &&
21
+ valid_time_zone?(value)
22
+ end
23
+
24
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveValidation
2
- VERSION = '4.0.5'.freeze
2
+ VERSION = '4.0.6'.freeze
3
3
  end
@@ -1,10 +1,12 @@
1
1
  require 'active_model'
2
2
  require 'active_support'
3
+ require 'active_support/core_ext/time/zones'
3
4
  require 'active_validation/version'
4
5
 
5
6
  ACTIVE_VALIDATION_VALIDATORS ||= %w(
6
7
  alpha alpha_numeric base64 boolean coordinate credit_card currency cusip email equality hex imei
7
- ip isbn isin mac_address name password phone sedol slug ssn tracking_number type url username uuid
8
+ ip isbn isin mac_address name password phone sedol slug ssn time_zone tracking_number type url
9
+ username uuid
8
10
  ).freeze
9
11
 
10
12
  ACTIVE_VALIDATION_VALIDATORS.each do |file_name|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.5
4
+ version: 4.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2016-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -200,6 +200,7 @@ files:
200
200
  - lib/active_validation/validators/sedol_validator.rb
201
201
  - lib/active_validation/validators/slug_validator.rb
202
202
  - lib/active_validation/validators/ssn_validator.rb
203
+ - lib/active_validation/validators/time_zone_validator.rb
203
204
  - lib/active_validation/validators/tracking_number_validator.rb
204
205
  - lib/active_validation/validators/type_validator.rb
205
206
  - lib/active_validation/validators/url_validator.rb