kangal 0.1.2 → 1.0.0

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: eb2722a5dfceae4f70173853595ce1b8fb27b55e
4
- data.tar.gz: 084a51fdb1e192a443c33816d32eba501c8ce7ce
3
+ metadata.gz: 3acd4dd252c9499dea9e2a495b70654b30da0237
4
+ data.tar.gz: 4c24cb321d8c94cdc92c1c0b8e2a0b78898b7c5d
5
5
  SHA512:
6
- metadata.gz: ab0b9b64d7f2fe4e575668a2df96775c5dba7cf3861f6a809159b9b9d8955c59f84f1437524d26198a097e59db3804b82898a79ea8ee5fd45876265c69fcf912
7
- data.tar.gz: ced4d242ee9f6331a1eea02b333ecbb668ea4743bd659b2cd8e4c1bd7d839318088bb4984f49188ba52ad7ac400a530a4dc43d18f266f79b66df5183eb5b1f60
6
+ metadata.gz: ed735ceba4170c3df5b27d3bfa486a38bf4f994c2a8aa76050fe9e0799c97f6e3bb217bbc9c27cf64fff74e30b0896e1511d5538d58ee125a2da2e0ad3659111
7
+ data.tar.gz: 500ee8f85e4046dbb2026eb60757ba2521913e97ccfc91f9bdf0ffd983257f8ef9260306f21825f05d3b60a9ddf475a0d081e22323239dc78071f2d758c2a70a
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/version_tmp
17
17
  tmp
18
18
  .idea
19
19
  .swp
20
+ .rvmrc
@@ -1,19 +1,21 @@
1
+ #### 1.0.0
1
2
 
2
- #### [Current]
3
+ * [2b6753e](../../commit/2b6753e) #3 subdomain validator added __(Muhammet DİLEK)__
3
4
 
4
- ####
5
- * [bca3a4c](bca3a4c) add CHANGELOG.md __(Onur Ozgur OZKAN)__
6
- * [8a5dd69](8a5dd69) #7 add travis-ci flag to README.md __(Onur Ozgur OZKAN)__
7
- * [5a48bab](5a48bab) #2 fixed email format for spec __(Onur Ozgur OZKAN)__
8
- * [382d3d1](382d3d1) #7 add travis-ci service __(Onur Ozgur OZKAN)__
9
- * [85ad341](85ad341) Improve README.md __(Onur Ozgur OZKAN)__
10
- * [4a986b9](4a986b9) #5 add locale system and files __(Onur Ozgur OZKAN)__
11
- * [80f0aea](80f0aea) #2 add email validation __(Onur Ozgur OZKAN)__
12
- * [189bbba](189bbba) #2 add spec for email __(Onur Ozgur OZKAN)__
13
- * [42b68b5](42b68b5) #4 setup rspec and rake __(Onur Ozgur OZKAN)__
14
- * [34cc03a](34cc03a) #4 set rspec and rake __(Onur Ozgur OZKAN)__
15
- * [3d0b486](3d0b486) #1 fix license.txt __(Onur Ozgur OZKAN)__
16
- * [cd9ed2e](cd9ed2e) #1 convert double quotes to single quotes __(Onur Ozgur OZKAN)__
17
- * [c9896cb](c9896cb) #1 setup Code Climate and Gemnasium __(Onur Ozgur OZKAN)__
18
- * [8ef9ff8](8ef9ff8) #1 setup gem __(Onur Ozgur OZKAN)__
19
- * [29e3e1e](29e3e1e) #1 setup gem __(Onur Ozgur OZKAN)__
5
+ #### 0.1.0
6
+
7
+ * [bca3a4c](../../commit/bca3a4c) add CHANGELOG.md __(Onur Ozgur OZKAN)__
8
+ * [8a5dd69](../../commit/8a5dd69) #7 add travis-ci flag to README.md __(Onur Ozgur OZKAN)__
9
+ * [5a48bab](../../commit/5a48bab) #2 fixed email format for spec __(Onur Ozgur OZKAN)__
10
+ * [382d3d1](../../commit/382d3d1) #7 add travis-ci service __(Onur Ozgur OZKAN)__
11
+ * [85ad341](../../commit/85ad341) Improve README.md __(Onur Ozgur OZKAN)__
12
+ * [4a986b9](../../commit/4a986b9) #5 add locale system and files __(Onur Ozgur OZKAN)__
13
+ * [80f0aea](../../commit/80f0aea) #2 add email validation __(Onur Ozgur OZKAN)__
14
+ * [189bbba](../../commit/189bbba) #2 add spec for email __(Onur Ozgur OZKAN)__
15
+ * [42b68b5](../../commit/42b68b5) #4 setup rspec and rake __(Onur Ozgur OZKAN)__
16
+ * [34cc03a](../../commit/34cc03a) #4 set rspec and rake __(Onur Ozgur OZKAN)__
17
+ * [3d0b486](../../commit/3d0b486) #1 fix license.txt __(Onur Ozgur OZKAN)__
18
+ * [cd9ed2e](../../commit/cd9ed2e) #1 convert double quotes to single quotes __(Onur Ozgur OZKAN)__
19
+ * [c9896cb](../../commit/c9896cb) #1 setup Code Climate and Gemnasium __(Onur Ozgur OZKAN)__
20
+ * [8ef9ff8](../../commit/8ef9ff8) #1 setup gem __(Onur Ozgur OZKAN)__
21
+ * [29e3e1e](../../commit/29e3e1e) #1 setup gem __(Onur Ozgur OZKAN)__
data/README.md CHANGED
@@ -23,15 +23,14 @@ In your Gemfile
23
23
  gem 'kangal'
24
24
  ```
25
25
 
26
-
27
- In your code
28
-
26
+ ### Email Validator
29
27
  ```ruby
30
28
  require 'kangal'
31
29
  class User
32
30
  include ActiveModel::Validations
33
31
  attr_accessor :email
34
32
 
33
+ # Email validator
35
34
  validates :email, presence: :true, email: :true
36
35
  end
37
36
 
@@ -47,6 +46,43 @@ p.email = "Onur Ozgur <info@lab2023.com>"
47
46
  p.valid? # => false
48
47
  ```
49
48
 
49
+ ### Subdomain Validator
50
+ ```ruby
51
+ require 'kangal'
52
+ class User
53
+ include ActiveModel::Validations
54
+ attr_accessor :subdomain
55
+
56
+ # Subdomain validator
57
+ validates :subdomain, subdomain: true
58
+
59
+ # Or
60
+ validates :subdomain, subdomain: { :reserved => %w(foo bar) }
61
+ end
62
+
63
+
64
+ p = User.new
65
+ p.subdomain = "wwww"
66
+ p.valid? # => false
67
+
68
+ p.subdomain = "https"
69
+ p.valid? # => false
70
+
71
+ p.subdomain = "-lab2023"
72
+ p.valid? # => false
73
+
74
+ p.subdomain = "-lab2023-"
75
+ p.valid? # => false
76
+
77
+ p.subdomain = "foo"
78
+ p.valid? # => false
79
+
80
+ p.email = "lab2023"
81
+ p.valid? # => true
82
+ ```
83
+
84
+ **Default reserved names:** www, ftp, mail, pop, smtp, admin, ssl, sftp, http, https
85
+
50
86
 
51
87
  ## Bugs and Feedback
52
88
 
@@ -2,4 +2,9 @@ en:
2
2
  kangal:
3
3
  validations:
4
4
  email:
5
- invalid: 'is invalid'
5
+ invalid: 'is invalid'
6
+ subdomain:
7
+ reserved: 'cannot be a reserved name'
8
+ character: 'must have between 3 and 63 letters'
9
+ hyphen: 'cannot start or end with a hyphen'
10
+ alphanumeric: 'must be alphanumeric; A-Z, 0-9 or hyphen'
@@ -2,4 +2,9 @@ tr:
2
2
  kangal:
3
3
  validations:
4
4
  email:
5
- invalid: 'geçersizdir.'
5
+ invalid: 'geçersizdir.'
6
+ subdomain:
7
+ reserved: 'bu isim alınamaz'
8
+ character: '3 ile 63 karakter arasında olmalıdır'
9
+ hyphen: 'tire ile başalayamaz veya bitemez'
10
+ alphanumeric: 'alfanümerik olmalıdır; A-Z, 0-9 veya tire'
@@ -1,4 +1,5 @@
1
1
  require 'kangal/version'
2
2
  require 'kangal/email'
3
+ require 'kangal/subdomain'
3
4
 
4
5
  I18n.load_path += Dir.glob(File.expand_path('../../config/locales/**/*',__FILE__))
@@ -0,0 +1,17 @@
1
+ require 'active_model'
2
+ require 'active_model/validations'
3
+
4
+ class SubdomainValidator < ActiveModel::EachValidator
5
+ def validate_each(object, attribute, value)
6
+ return unless value.present?
7
+ reserved_names = %w(www ftp mail pop smtp admin ssl sftp http https)
8
+ reserved_names = options[:reserved] if options[:reserved]
9
+ if reserved_names.include?(value)
10
+ object.errors[attribute] << I18n.t(:reserved, scope: 'kangal.validations.subdomain')
11
+ end
12
+
13
+ object.errors[attribute] << I18n.t(:character, scope: 'kangal.validations.subdomain') unless (3..63) === value.length
14
+ object.errors[attribute] << I18n.t(:hyphen, scope: 'kangal.validations.subdomain') unless value =~ /^[^-].*[^-]$/i
15
+ object.errors[attribute] << I18n.t(:alphanumeric, scope: 'kangal.validations.subdomain') unless value =~ /^[a-z0-9\-]*$/i
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Kangal
2
- VERSION = '0.1.2'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ class Company < SpecModel
4
+ validates :subdomain, subdomain: true
5
+ end
6
+
7
+ describe 'Subdomain format' do
8
+
9
+ let(:invalid_subdomains) do
10
+ %w(-lab2023 https, ab)
11
+ end
12
+
13
+ let(:valid_subdomains) do
14
+ %w(lab2023 lab2023-internet)
15
+ end
16
+
17
+ it 'should be invalid' do
18
+ invalid_subdomains.each { |subdomain| Company.new(subdomain: subdomain).valid?.should be_false }
19
+ end
20
+
21
+ it 'should be valid' do
22
+ valid_subdomains.each { |subdomain| Company.new(subdomain: subdomain).valid?.should be_true }
23
+ end
24
+
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kangal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lab2023
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-25 00:00:00.000000000 Z
12
+ date: 2013-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -101,9 +101,11 @@ files:
101
101
  - kangal.gemspec
102
102
  - lib/kangal.rb
103
103
  - lib/kangal/email.rb
104
+ - lib/kangal/subdomain.rb
104
105
  - lib/kangal/version.rb
105
106
  - spec/email_spec.rb
106
107
  - spec/spec_helper.rb
108
+ - spec/subdomain_spec.rb
107
109
  homepage: https://github.com/kebab-project/kangal
108
110
  licenses:
109
111
  - MIT