subdomain_validation 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 08fffa3ec8c726790ab4cbebd6b6e0fa2dfab0ed
4
+ data.tar.gz: fa8e0939c1e2f80042c7e9da9d7c3287d98c9bc8
5
+ SHA512:
6
+ metadata.gz: 4d1a93984dc7e7123f9d79cc0fb947b40d807d82b4e231d06a7ad1337562724f2b0371323eb74dac441d26edd8be66d371992c211ebf877fc9f5af53bfc115d7
7
+ data.tar.gz: 398c4c74d4230721910686c7d40a90adc8a2424586a72e9319c18306c389104314d71942c771c7979364064b9be3f717cef5373b9a196f7ab0ad5e18d4afc64e
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Gitobi LLC.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # SubdomainValidation
2
+
3
+ Subdomain validator for Rails
4
+
5
+ Reference: [RFC 1035 - Domain names - implementation and specification](https://tools.ietf.org/html/rfc1035)
6
+
7
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SubdomainValidation'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
@@ -0,0 +1,7 @@
1
+ en:
2
+ subdomain_validation:
3
+ errors:
4
+ messages:
5
+ label: "can only include letters and numbers and \"-\""
6
+ first_character: "can't start with \"-\""
7
+ last_character: "can't end with \"-\""
@@ -0,0 +1,7 @@
1
+ ja:
2
+ subdomain_validation:
3
+ errors:
4
+ messages:
5
+ label: "は半角英数とハイフンのみ使用できます"
6
+ first_character: "は頭文字にハイフンを使用することはできません"
7
+ last_character: "は末尾にハイフンを使用することはできません"
@@ -0,0 +1,4 @@
1
+ module SubdomainValidation
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,32 @@
1
+ module SubdomainValidation
2
+ class SubdomainValidator < ActiveModel::EachValidator
3
+ def validate_each(record, attribute, value)
4
+
5
+ if value.blank?
6
+ record.errors.add(attribute, :blank)
7
+ return
8
+ end
9
+
10
+ record.errors.add(attribute, :taken) if reserved_name.include?(value)
11
+ record.errors.add(attribute, :too_short, count: 3) if value.length < 3
12
+ record.errors.add(attribute, :too_long, count: 63) if 63 < value.length
13
+
14
+ record.errors.add(attribute, I18n.t('subdomain_validation.errors.messages.label')) if value =~ /[^A-Za-z0-9\-]/
15
+
16
+ record.errors.add(attribute, I18n.t('subdomain_validation.errors.messages.first_character')) if value =~ /^-/
17
+ record.errors.add(attribute, I18n.t('subdomain_validation.errors.messages.last_character')) if value =~ /-$/
18
+ end
19
+
20
+ private
21
+ def reserved_name
22
+ case options[:reserved_name]
23
+ when nil
24
+ %w(www http https ftp sftp ssl ns mx pop smtp admin mail users)
25
+ when false
26
+ []
27
+ else
28
+ options[:reserved_name]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module SubdomainValidation
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'subdomain_validation/subdomain_validator'
2
+ require 'subdomain_validation/engine'
3
+
4
+ module SubdomainValidation
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :subdomain_validation do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subdomain_validation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Rui Onodera
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.2.6
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.2.6
33
+ - !ruby/object:Gem::Dependency
34
+ name: sqlite3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec-rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: factory_girl_rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry-byebug
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: Subdomain validator for Rails application.
90
+ email:
91
+ - deraru@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - MIT-LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - config/locales/en.yml
100
+ - config/locales/ja.yml
101
+ - lib/subdomain_validation.rb
102
+ - lib/subdomain_validation/engine.rb
103
+ - lib/subdomain_validation/subdomain_validator.rb
104
+ - lib/subdomain_validation/version.rb
105
+ - lib/tasks/subdomain_validation_tasks.rake
106
+ homepage: https://github.com/gitobi/subdomain_validation
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.5.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Subdomain validator for Rails
130
+ test_files: []