moca_rlibs 0.0.4 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/rlibs.iml +8 -10
- data/Gemfile.lock +11 -5
- data/README.md +79 -2
- data/lib/moca_rlibs/active_model_validators/ip.rb +28 -0
- data/lib/moca_rlibs/active_model_validators/only_alpha.rb +18 -0
- data/lib/moca_rlibs/active_model_validators/only_alpha_numeric.rb +18 -0
- data/lib/moca_rlibs/active_model_validators/only_ascii.rb +18 -0
- data/lib/moca_rlibs/active_model_validators/only_numbers.rb +18 -0
- data/lib/moca_rlibs/active_model_validators/only_printable.rb +18 -0
- data/lib/moca_rlibs/grape_validators/ip_address.rb +36 -0
- data/lib/moca_rlibs/grape_validators/only_printable.rb +1 -1
- data/lib/moca_rlibs/kernel.rb +9 -0
- data/lib/moca_rlibs/version.rb +1 -1
- data/lib/moca_rlibs.rb +9 -0
- data/moca_rlibs.gemspec +6 -0
- metadata +39 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: feea6203c6583ea008e12222e3392f0d9c2dcf1632c29c9984320464e2c26d6d
|
4
|
+
data.tar.gz: df4085914926e57d3126d00cd0b85759aebe3b6cab4794a9da973dc70f2b723d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69a25352440a1b39b5c46599fbe650eb189d590a5ed9c28a9cb7d604b0bc871400e56d39673beb08a6dd8e0fb9b848e56a63748d301b56107f2f198c099546ef
|
7
|
+
data.tar.gz: f098c4923f4723d24805a8a950f97ab82b2a4608bc239385e2e1bd0229eca11f1384c0a3d3270af1405d66f6dc5e02733ba361894c26fa58571cbbeadf7650c1
|
data/.idea/rlibs.iml
CHANGED
@@ -12,11 +12,11 @@
|
|
12
12
|
<orderEntry type="inheritedJdk" />
|
13
13
|
<orderEntry type="sourceFolder" forTests="false" />
|
14
14
|
<orderEntry type="library" scope="PROVIDED" name="activemodel (v6.1.4.1, rbenv: 3.0.2) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="activerecord (v6.1.4.1, rbenv: 3.0.2) [gem]" level="application" />
|
15
16
|
<orderEntry type="library" scope="PROVIDED" name="activesupport (v6.1.4.1, rbenv: 3.0.2) [gem]" level="application" />
|
16
17
|
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.0.2) [gem]" level="application" />
|
17
18
|
<orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, rbenv: 3.0.2) [gem]" level="application" />
|
18
19
|
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.22, rbenv: 3.0.2) [gem]" level="application" />
|
19
|
-
<orderEntry type="library" scope="PROVIDED" name="codecov (v0.6.0, rbenv: 3.0.2) [gem]" level="application" />
|
20
20
|
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.9, rbenv: 3.0.2) [gem]" level="application" />
|
21
21
|
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4, rbenv: 3.0.2) [gem]" level="application" />
|
22
22
|
<orderEntry type="library" scope="PROVIDED" name="docile (v1.4.0, rbenv: 3.0.2) [gem]" level="application" />
|
@@ -33,21 +33,19 @@
|
|
33
33
|
<orderEntry type="library" scope="PROVIDED" name="mustermann (v1.1.1, rbenv: 3.0.2) [gem]" level="application" />
|
34
34
|
<orderEntry type="library" scope="PROVIDED" name="mustermann-grape (v1.0.1, rbenv: 3.0.2) [gem]" level="application" />
|
35
35
|
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.21.0, rbenv: 3.0.2) [gem]" level="application" />
|
36
|
-
<orderEntry type="library" scope="PROVIDED" name="parser (v3.0.
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v3.0.3.1, rbenv: 3.0.2) [gem]" level="application" />
|
37
37
|
<orderEntry type="library" scope="PROVIDED" name="rack (v2.2.3, rbenv: 3.0.2) [gem]" level="application" />
|
38
38
|
<orderEntry type="library" scope="PROVIDED" name="rack-accept (v0.4.5, rbenv: 3.0.2) [gem]" level="application" />
|
39
39
|
<orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, rbenv: 3.0.2) [gem]" level="application" />
|
40
40
|
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, rbenv: 3.0.2) [gem]" level="application" />
|
41
41
|
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, rbenv: 3.0.2) [gem]" level="application" />
|
42
|
-
<orderEntry type="library" scope="PROVIDED" name="rbs (v1.0.4, rbenv: 3.0.2) [gem]" level="application" />
|
43
42
|
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.1.1, rbenv: 3.0.2) [gem]" level="application" />
|
44
43
|
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, rbenv: 3.0.2) [gem]" level="application" />
|
45
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, rbenv: 3.0.2) [gem]" level="application" />
|
46
44
|
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.1, rbenv: 3.0.2) [gem]" level="application" />
|
47
45
|
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.1, rbenv: 3.0.2) [gem]" level="application" />
|
48
46
|
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2, rbenv: 3.0.2) [gem]" level="application" />
|
49
47
|
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.3, rbenv: 3.0.2) [gem]" level="application" />
|
50
|
-
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.
|
48
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.23.0, rbenv: 3.0.2) [gem]" level="application" />
|
51
49
|
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.13.0, rbenv: 3.0.2) [gem]" level="application" />
|
52
50
|
<orderEntry type="library" scope="PROVIDED" name="rubocop-performance (v1.12.0, rbenv: 3.0.2) [gem]" level="application" />
|
53
51
|
<orderEntry type="library" scope="PROVIDED" name="rubocop-rails (v2.12.4, rbenv: 3.0.2) [gem]" level="application" />
|
@@ -66,21 +64,21 @@
|
|
66
64
|
<option name="myRootTask">
|
67
65
|
<RakeTaskImpl id="rake">
|
68
66
|
<subtasks>
|
69
|
-
<RakeTaskImpl description="Build moca_rlibs-0.0.
|
67
|
+
<RakeTaskImpl description="Build moca_rlibs-0.0.4.gem into the pkg directory" fullCommand="build" id="build" />
|
70
68
|
<RakeTaskImpl id="build">
|
71
69
|
<subtasks>
|
72
|
-
<RakeTaskImpl description="Generate SHA512 checksum if moca_rlibs-0.0.
|
70
|
+
<RakeTaskImpl description="Generate SHA512 checksum if moca_rlibs-0.0.4.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
|
73
71
|
</subtasks>
|
74
72
|
</RakeTaskImpl>
|
75
73
|
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
76
74
|
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
77
|
-
<RakeTaskImpl description="Build and install moca_rlibs-0.0.
|
75
|
+
<RakeTaskImpl description="Build and install moca_rlibs-0.0.4.gem into system gems" fullCommand="install" id="install" />
|
78
76
|
<RakeTaskImpl id="install">
|
79
77
|
<subtasks>
|
80
|
-
<RakeTaskImpl description="Build and install moca_rlibs-0.0.
|
78
|
+
<RakeTaskImpl description="Build and install moca_rlibs-0.0.4.gem into system gems without network access" fullCommand="install:local" id="local" />
|
81
79
|
</subtasks>
|
82
80
|
</RakeTaskImpl>
|
83
|
-
<RakeTaskImpl description="Create tag v0.0.
|
81
|
+
<RakeTaskImpl description="Create tag v0.0.4 and build and push moca_rlibs-0.0.4.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
84
82
|
<RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
|
85
83
|
<RakeTaskImpl description="" fullCommand="default" id="default" />
|
86
84
|
<RakeTaskImpl description="" fullCommand="release" id="release" />
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
moca_rlibs (0.0.
|
4
|
+
moca_rlibs (0.0.8)
|
5
5
|
activemodel
|
6
|
+
activerecord
|
6
7
|
activesupport
|
7
8
|
email_validator
|
8
9
|
grape
|
@@ -13,6 +14,9 @@ GEM
|
|
13
14
|
specs:
|
14
15
|
activemodel (6.1.4.1)
|
15
16
|
activesupport (= 6.1.4.1)
|
17
|
+
activerecord (6.1.4.1)
|
18
|
+
activemodel (= 6.1.4.1)
|
19
|
+
activesupport (= 6.1.4.1)
|
16
20
|
activesupport (6.1.4.1)
|
17
21
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
22
|
i18n (>= 1.6, < 2)
|
@@ -61,7 +65,7 @@ GEM
|
|
61
65
|
mustermann-grape (1.0.1)
|
62
66
|
mustermann (>= 1.0.0)
|
63
67
|
parallel (1.21.0)
|
64
|
-
parser (3.0.
|
68
|
+
parser (3.0.3.1)
|
65
69
|
ast (~> 2.4.1)
|
66
70
|
rack (2.2.3)
|
67
71
|
rack-accept (0.4.5)
|
@@ -70,7 +74,7 @@ GEM
|
|
70
74
|
rack (>= 1.0, < 3)
|
71
75
|
rainbow (3.0.0)
|
72
76
|
rake (13.0.6)
|
73
|
-
regexp_parser (2.
|
77
|
+
regexp_parser (2.2.0)
|
74
78
|
rexml (3.2.5)
|
75
79
|
rspec (3.10.0)
|
76
80
|
rspec-core (~> 3.10.0)
|
@@ -85,7 +89,7 @@ GEM
|
|
85
89
|
diff-lcs (>= 1.2.0, < 2.0)
|
86
90
|
rspec-support (~> 3.10.0)
|
87
91
|
rspec-support (3.10.3)
|
88
|
-
rubocop (1.
|
92
|
+
rubocop (1.23.0)
|
89
93
|
parallel (~> 1.10)
|
90
94
|
parser (>= 3.0.0.0)
|
91
95
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -94,7 +98,7 @@ GEM
|
|
94
98
|
rubocop-ast (>= 1.12.0, < 2.0)
|
95
99
|
ruby-progressbar (~> 1.7)
|
96
100
|
unicode-display_width (>= 1.4.0, < 3.0)
|
97
|
-
rubocop-ast (1.
|
101
|
+
rubocop-ast (1.14.0)
|
98
102
|
parser (>= 3.0.1.1)
|
99
103
|
rubocop-performance (1.12.0)
|
100
104
|
rubocop (>= 1.7.0, < 2.0)
|
@@ -114,6 +118,7 @@ GEM
|
|
114
118
|
simplecov-html (0.12.3)
|
115
119
|
simplecov_json_formatter (0.1.3)
|
116
120
|
slack-notifier (2.4.0)
|
121
|
+
sqlite3 (1.4.2)
|
117
122
|
tzinfo (2.0.4)
|
118
123
|
concurrent-ruby (~> 1.0)
|
119
124
|
unicode-display_width (2.1.0)
|
@@ -134,6 +139,7 @@ DEPENDENCIES
|
|
134
139
|
rubocop-rails
|
135
140
|
rubocop-rspec
|
136
141
|
simplecov
|
142
|
+
sqlite3
|
137
143
|
|
138
144
|
RUBY VERSION
|
139
145
|
ruby 3.0.2p107
|
data/README.md
CHANGED
@@ -18,6 +18,69 @@ MocaRlibs::Docker.running_on_docker?
|
|
18
18
|
MocaRlibs::CodeBuild.running_on_codebuild?
|
19
19
|
```
|
20
20
|
|
21
|
+
## ActiveModelカスタムバリデーション
|
22
|
+
半角アルファベットのみを許可する
|
23
|
+
```ruby
|
24
|
+
class UserModel
|
25
|
+
include ActiveModel::Validations
|
26
|
+
|
27
|
+
validates :user_name, only_alpha: true
|
28
|
+
end
|
29
|
+
```
|
30
|
+
半角アルファベットと数字のみを許可する
|
31
|
+
```ruby
|
32
|
+
class UserModel
|
33
|
+
include ActiveModel::Validations
|
34
|
+
|
35
|
+
validates :user_name, only_alpha_numeric: true
|
36
|
+
end
|
37
|
+
```
|
38
|
+
数字のみの文字列を許可する
|
39
|
+
```ruby
|
40
|
+
class UserModel
|
41
|
+
include ActiveModel::Validations
|
42
|
+
|
43
|
+
validates :user_name, only_numbers: true
|
44
|
+
end
|
45
|
+
```
|
46
|
+
アスキー文字のみの文字列を許可する
|
47
|
+
```ruby
|
48
|
+
class UserModel
|
49
|
+
include ActiveModel::Validations
|
50
|
+
|
51
|
+
validates :user_name, only_ascii: true
|
52
|
+
end
|
53
|
+
```
|
54
|
+
出力可能なアスキー文字のみかどうかをチェックする(半角英数字、一部の記号)
|
55
|
+
```ruby
|
56
|
+
class UserModel
|
57
|
+
include ActiveModel::Validations
|
58
|
+
|
59
|
+
validates :user_name, only_printable: true
|
60
|
+
end
|
61
|
+
```
|
62
|
+
メールアドレスのフォーマットチェック
|
63
|
+
https://github.com/K-and-R/email_validator
|
64
|
+
```ruby
|
65
|
+
class UserModel
|
66
|
+
include ActiveModel::Validations
|
67
|
+
|
68
|
+
validates :user_email, email: true
|
69
|
+
validates :user_email, email: { mode: :strict, require_fqdn: true }
|
70
|
+
validates :user_email, email: { domain: 'example.com' }
|
71
|
+
end
|
72
|
+
```
|
73
|
+
IPアドレスのフォーマットをチェックする
|
74
|
+
```ruby
|
75
|
+
class UserModel
|
76
|
+
include ActiveModel::Validations
|
77
|
+
|
78
|
+
validates :last_login_ip, ip: true
|
79
|
+
validates :last_login_ip, ip: { version: :v4 }
|
80
|
+
validates :last_login_ip, ip: { version: :v6 }
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
21
84
|
## Grapeカスタムバリデーション
|
22
85
|
メールアドレスのフォーマットチェック(簡易チェック)
|
23
86
|
```ruby
|
@@ -112,13 +175,21 @@ params do
|
|
112
175
|
requires :text, type: String, only_alpha_numeric: true
|
113
176
|
end
|
114
177
|
```
|
115
|
-
出力可能なアスキー文字しか含まれないこと
|
116
|
-
(半角英数字、半角スペース、一部の表示可能な記号)
|
178
|
+
出力可能なアスキー文字しか含まれないこと(半角英数字、一部の表示可能な記号)
|
117
179
|
```ruby
|
118
180
|
params do
|
119
181
|
requires :text, type: String, only_printable: true
|
120
182
|
end
|
121
183
|
```
|
184
|
+
IPアドレスのフォーマットをチェックする
|
185
|
+
```ruby
|
186
|
+
params do
|
187
|
+
optional :ip, type: String, ip_address: true
|
188
|
+
optional :ipv4, type: String, ip_address: :v4
|
189
|
+
optional :ipv6, type: String, ip_address: :v6
|
190
|
+
end
|
191
|
+
```
|
192
|
+
|
122
193
|
## Slack通知送信用クラス
|
123
194
|
```ruby
|
124
195
|
# インスタンス化
|
@@ -152,3 +223,9 @@ MocaRlibs::SlackNotifier.send('some message')
|
|
152
223
|
# @param [String] webhook Web Hook URL
|
153
224
|
MocaRlibs::SlackNotifier.error(StandardError.new('some error occurred'))
|
154
225
|
```
|
226
|
+
|
227
|
+
## ruby拡張(Kernelモジュール)
|
228
|
+
pythonのpassと同様、「何もしないこと」を明示的に示すため
|
229
|
+
```ruby
|
230
|
+
pass
|
231
|
+
```
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require 'active_support/all'
|
5
|
+
require 'resolv'
|
6
|
+
|
7
|
+
module ActiveModel::Validations
|
8
|
+
# IPアドレスのフォーマットをチェックする
|
9
|
+
class IpValidator < ::ActiveModel::EachValidator
|
10
|
+
PERMITTED_VERSION = %i[v4 v6].freeze
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
options[:version] ||= %i[v4 v6]
|
14
|
+
options[:version] = Array(options[:version])
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate_each(record, attribute, value)
|
19
|
+
return if value.blank?
|
20
|
+
|
21
|
+
value = value.presence.to_s
|
22
|
+
return if options[:version].include?(:v4) && ::Resolv::IPv4::Regex.match?(value)
|
23
|
+
return if options[:version].include?(:v6) && ::Resolv::IPv6::Regex.match?(value)
|
24
|
+
|
25
|
+
record.errors.add('invalid ip format')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
module ActiveModel::Validations
|
7
|
+
# 文字列が半角アルファベットのみであることをチェックする
|
8
|
+
class OnlyAlphaValidator < ActiveModel::EachValidator
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
return if value.blank?
|
11
|
+
|
12
|
+
value = value.presence.to_s
|
13
|
+
return if value.match?(/\A[a-zA-Z]*\z/)
|
14
|
+
|
15
|
+
record.errors.add('contain invalid characters (only alphabets)')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
module ActiveModel::Validations
|
7
|
+
# 文字列が半角英数字のみであることをチェックする
|
8
|
+
class OnlyAlphaNumericValidator < ActiveModel::EachValidator
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
return if value.blank?
|
11
|
+
|
12
|
+
value = value.presence.to_s
|
13
|
+
return if value.match?(/\A[a-zA-Z0-9]*\z/)
|
14
|
+
|
15
|
+
record.errors.add('contain invalid characters (only numbers and alphabets)')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
module ActiveModel::Validations
|
7
|
+
# アスキー文字のみを許可する
|
8
|
+
class OnlyAsciiValidator < ActiveModel::EachValidator
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
return if value.blank?
|
11
|
+
|
12
|
+
value = value.presence.to_s
|
13
|
+
return if value.match?(/\A[\u0000-\u007F]*\z/)
|
14
|
+
|
15
|
+
record.errors.add('contain non-ascii characters')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
module ActiveModel::Validations
|
7
|
+
# 文字列が数字のみであることをチェックする
|
8
|
+
class OnlyNumbersValidator < ActiveModel::EachValidator
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
return if value.blank?
|
11
|
+
|
12
|
+
value = value.presence.to_s
|
13
|
+
return if value.match?(/\A[0-9]*\z/)
|
14
|
+
|
15
|
+
record.errors.add('contain invalid characters (only numbers)')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
module ActiveModel::Validations
|
7
|
+
# 出力可能なアスキー文字のみかどうかをチェックする(半角英数字+一部の記号)
|
8
|
+
class OnlyPrintableValidator < ActiveModel::EachValidator
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
return if value.blank?
|
11
|
+
|
12
|
+
value = value.presence.to_s
|
13
|
+
return if value.match?(%r{\A[a-zA-Z0-9!"#$%&'()*+,-./:;<=>?@\[\\\]^_`{|}~]*\z})
|
14
|
+
|
15
|
+
record.errors.add('contain invalid characters (only printable ascii characters)')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/all'
|
4
|
+
require 'grape'
|
5
|
+
require 'resolv'
|
6
|
+
|
7
|
+
module MocaRlibs::GrapeValidators
|
8
|
+
# 数値の最小値をチェック
|
9
|
+
class IpAddress < Grape::Validations::Base
|
10
|
+
def validate_param!(attr_name, params)
|
11
|
+
return if !@required && params[attr_name].blank?
|
12
|
+
|
13
|
+
version = @option.instance_of?(Proc) ? @option.call(params) : @option
|
14
|
+
value = params[attr_name].presence.to_s
|
15
|
+
return if validate_ip(version, value)
|
16
|
+
|
17
|
+
message = "invalid ip format: #{value}"
|
18
|
+
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def validate_ip(version, value)
|
24
|
+
case version
|
25
|
+
when :v4
|
26
|
+
return true if ::Resolv::IPv4::Regex.match?(value)
|
27
|
+
when :v6
|
28
|
+
return true if ::Resolv::IPv6::Regex.match?(value)
|
29
|
+
else
|
30
|
+
return true if ::Resolv::IPv4::Regex.match?(value)
|
31
|
+
return true if ::Resolv::IPv6::Regex.match?(value)
|
32
|
+
end
|
33
|
+
false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -4,7 +4,7 @@ require 'active_support/all'
|
|
4
4
|
require 'grape'
|
5
5
|
|
6
6
|
module MocaRlibs::GrapeValidators
|
7
|
-
# 出力可能なアスキー文字のみかどうかをチェックする(
|
7
|
+
# 出力可能なアスキー文字のみかどうかをチェックする(半角英数字+一部の記号)
|
8
8
|
class OnlyPrintable < Grape::Validations::Base
|
9
9
|
def validate_param!(attr_name, params)
|
10
10
|
return if !@required && params[attr_name].blank?
|
data/lib/moca_rlibs/version.rb
CHANGED
data/lib/moca_rlibs.rb
CHANGED
@@ -19,6 +19,7 @@ require_relative 'moca_rlibs/grape_validators/only_numbers'
|
|
19
19
|
require_relative 'moca_rlibs/grape_validators/only_alpha'
|
20
20
|
require_relative 'moca_rlibs/grape_validators/only_alpha_numeric'
|
21
21
|
require_relative 'moca_rlibs/grape_validators/only_printable'
|
22
|
+
require_relative 'moca_rlibs/grape_validators/ip_address'
|
22
23
|
require_relative 'moca_rlibs/grape_errors/bad_gateway'
|
23
24
|
require_relative 'moca_rlibs/grape_errors/bad_request'
|
24
25
|
require_relative 'moca_rlibs/grape_errors/conflict'
|
@@ -31,6 +32,14 @@ require_relative 'moca_rlibs/grape_errors/retry_required'
|
|
31
32
|
require_relative 'moca_rlibs/grape_errors/service_unavailable'
|
32
33
|
require_relative 'moca_rlibs/grape_errors/too_many_requests'
|
33
34
|
require_relative 'moca_rlibs/grape_errors/unauthorized'
|
35
|
+
require_relative 'moca_rlibs/active_model_validators/only_alpha'
|
36
|
+
require_relative 'moca_rlibs/active_model_validators/only_alpha_numeric'
|
37
|
+
require_relative 'moca_rlibs/active_model_validators/only_ascii'
|
38
|
+
require_relative 'moca_rlibs/active_model_validators/only_numbers'
|
39
|
+
require_relative 'moca_rlibs/active_model_validators/only_printable'
|
40
|
+
require_relative 'moca_rlibs/active_model_validators/ip'
|
41
|
+
|
42
|
+
require_relative 'moca_rlibs/kernel'
|
34
43
|
|
35
44
|
require 'active_model'
|
36
45
|
require 'email_validator'
|
data/moca_rlibs.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ['lib']
|
29
29
|
|
30
30
|
spec.add_dependency 'activemodel'
|
31
|
+
spec.add_dependency 'activerecord'
|
31
32
|
spec.add_dependency 'activesupport'
|
32
33
|
spec.add_dependency 'email_validator'
|
33
34
|
spec.add_dependency 'grape'
|
@@ -43,4 +44,9 @@ Gem::Specification.new do |spec|
|
|
43
44
|
spec.add_development_dependency 'rubocop-rails'
|
44
45
|
spec.add_development_dependency 'rubocop-rspec'
|
45
46
|
spec.add_development_dependency 'simplecov'
|
47
|
+
spec.add_development_dependency 'sqlite3'
|
48
|
+
|
49
|
+
spec.metadata = {
|
50
|
+
'rubygems_mfa_required' => 'true'
|
51
|
+
}
|
46
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moca_rlibs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mocaberos
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: activesupport
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,6 +234,20 @@ dependencies:
|
|
220
234
|
- - ">="
|
221
235
|
- !ruby/object:Gem::Version
|
222
236
|
version: '0'
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: sqlite3
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - ">="
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
223
251
|
description: A toolset for ruby and rails.
|
224
252
|
email:
|
225
253
|
- mocaberos@gmail.com
|
@@ -249,6 +277,12 @@ files:
|
|
249
277
|
- buildspec.yml
|
250
278
|
- docker/scripts/test.sh
|
251
279
|
- lib/moca_rlibs.rb
|
280
|
+
- lib/moca_rlibs/active_model_validators/ip.rb
|
281
|
+
- lib/moca_rlibs/active_model_validators/only_alpha.rb
|
282
|
+
- lib/moca_rlibs/active_model_validators/only_alpha_numeric.rb
|
283
|
+
- lib/moca_rlibs/active_model_validators/only_ascii.rb
|
284
|
+
- lib/moca_rlibs/active_model_validators/only_numbers.rb
|
285
|
+
- lib/moca_rlibs/active_model_validators/only_printable.rb
|
252
286
|
- lib/moca_rlibs/codebuild.rb
|
253
287
|
- lib/moca_rlibs/docker.rb
|
254
288
|
- lib/moca_rlibs/grape_errors/bad_gateway.rb
|
@@ -267,6 +301,7 @@ files:
|
|
267
301
|
- lib/moca_rlibs/grape_validators/email_rfc.rb
|
268
302
|
- lib/moca_rlibs/grape_validators/email_strict.rb
|
269
303
|
- lib/moca_rlibs/grape_validators/ends_with.rb
|
304
|
+
- lib/moca_rlibs/grape_validators/ip_address.rb
|
270
305
|
- lib/moca_rlibs/grape_validators/length.rb
|
271
306
|
- lib/moca_rlibs/grape_validators/max.rb
|
272
307
|
- lib/moca_rlibs/grape_validators/min.rb
|
@@ -277,6 +312,7 @@ files:
|
|
277
312
|
- lib/moca_rlibs/grape_validators/only_printable.rb
|
278
313
|
- lib/moca_rlibs/grape_validators/starts_with.rb
|
279
314
|
- lib/moca_rlibs/grape_validators/url.rb
|
315
|
+
- lib/moca_rlibs/kernel.rb
|
280
316
|
- lib/moca_rlibs/service.rb
|
281
317
|
- lib/moca_rlibs/slack_notifier.rb
|
282
318
|
- lib/moca_rlibs/version.rb
|
@@ -285,9 +321,7 @@ homepage: https://github.com/mocaberos/rlibs
|
|
285
321
|
licenses:
|
286
322
|
- MIT
|
287
323
|
metadata:
|
288
|
-
|
289
|
-
source_code_uri: https://github.com/mocaberos/rlibs
|
290
|
-
changelog_uri: https://github.com/mocaberos/rlibs/blob/master/CHANGELOG.md
|
324
|
+
rubygems_mfa_required: 'true'
|
291
325
|
post_install_message:
|
292
326
|
rdoc_options: []
|
293
327
|
require_paths:
|