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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +19 -17
- data/README.md +39 -3
- data/config/locales/en.yml +6 -1
- data/config/locales/tr.yml +6 -1
- data/lib/kangal.rb +1 -0
- data/lib/kangal/subdomain.rb +17 -0
- data/lib/kangal/version.rb +1 -1
- data/spec/subdomain_spec.rb +25 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3acd4dd252c9499dea9e2a495b70654b30da0237
|
4
|
+
data.tar.gz: 4c24cb321d8c94cdc92c1c0b8e2a0b78898b7c5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed735ceba4170c3df5b27d3bfa486a38bf4f994c2a8aa76050fe9e0799c97f6e3bb217bbc9c27cf64fff74e30b0896e1511d5538d58ee125a2da2e0ad3659111
|
7
|
+
data.tar.gz: 500ee8f85e4046dbb2026eb60757ba2521913e97ccfc91f9bdf0ffd983257f8ef9260306f21825f05d3b60a9ddf475a0d081e22323239dc78071f2d758c2a70a
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
+
#### 1.0.0
|
1
2
|
|
2
|
-
|
3
|
+
* [2b6753e](../../commit/2b6753e) #3 subdomain validator added __(Muhammet DİLEK)__
|
3
4
|
|
4
|
-
####
|
5
|
-
|
6
|
-
* [
|
7
|
-
* [
|
8
|
-
* [
|
9
|
-
* [
|
10
|
-
* [
|
11
|
-
* [
|
12
|
-
* [
|
13
|
-
* [
|
14
|
-
* [
|
15
|
-
* [
|
16
|
-
* [
|
17
|
-
* [
|
18
|
-
* [
|
19
|
-
* [
|
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
|
|
data/config/locales/en.yml
CHANGED
@@ -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'
|
data/config/locales/tr.yml
CHANGED
@@ -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'
|
data/lib/kangal.rb
CHANGED
@@ -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
|
data/lib/kangal/version.rb
CHANGED
@@ -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.
|
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-
|
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
|