moca_rlibs 0.0.4 → 0.0.5

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
  SHA256:
3
- metadata.gz: d56de38ddc6cf57ad65b710c31020762a8eb6c0986a2dc0d4bdef1f32a679c21
4
- data.tar.gz: eed1cd31a40b943240e748a803de37e2bf306f6c63fecda87cd7fabe1cb16d0a
3
+ metadata.gz: 18678bc1db494587ea1476c5c719f41911d55723caf5a3106a77eb24b0713aa6
4
+ data.tar.gz: e0c9dbbb335aab1afc25b7d720afdf50badff88966eb30483d23874aa3c838e8
5
5
  SHA512:
6
- metadata.gz: bc9da672d7425509fabea361d88ce40fd716dc0999d3a08c54be4cea20ceb5eaf780224fee305d82fd34b3b222d07038059e4746960ece674fd00d9bd72eebdd
7
- data.tar.gz: 3f355f47f10b8c21a7c23bdf944b7863110cd4a02316b843631e965a272b7c46798c76ac76f96f8bf047e4ab46c85ae06b2c522e22c36e1729f4fd5f0aa9722a
6
+ metadata.gz: efb1dea159fac373f90700da583cbe8ab27dbc9750a2adfbdb217fb8a2f0867b3108c53eeae655f4cf9ec2f4b82cb82a281d51d27305c0c60e425c560d9e9c79
7
+ data.tar.gz: e693ee291cc2484515b51f66dcb37cae35ec084369c2f8e6d3f958023e2a60641b8b729c5012653eaa3e79501cfd089fe3a20198321c474826539bb73c02cad0
data/.idea/rlibs.iml CHANGED
@@ -12,6 +12,7 @@
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" />
@@ -33,7 +34,7 @@
33
34
  <orderEntry type="library" scope="PROVIDED" name="mustermann (v1.1.1, rbenv: 3.0.2) [gem]" level="application" />
34
35
  <orderEntry type="library" scope="PROVIDED" name="mustermann-grape (v1.0.1, rbenv: 3.0.2) [gem]" level="application" />
35
36
  <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.2.0, rbenv: 3.0.2) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="parser (v3.0.3.0, rbenv: 3.0.2) [gem]" level="application" />
37
38
  <orderEntry type="library" scope="PROVIDED" name="rack (v2.2.3, rbenv: 3.0.2) [gem]" level="application" />
38
39
  <orderEntry type="library" scope="PROVIDED" name="rack-accept (v0.4.5, rbenv: 3.0.2) [gem]" level="application" />
39
40
  <orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, rbenv: 3.0.2) [gem]" level="application" />
@@ -47,7 +48,7 @@
47
48
  <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.1, rbenv: 3.0.2) [gem]" level="application" />
48
49
  <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2, rbenv: 3.0.2) [gem]" level="application" />
49
50
  <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.22.3, rbenv: 3.0.2) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.23.0, rbenv: 3.0.2) [gem]" level="application" />
51
52
  <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.13.0, rbenv: 3.0.2) [gem]" level="application" />
52
53
  <orderEntry type="library" scope="PROVIDED" name="rubocop-performance (v1.12.0, rbenv: 3.0.2) [gem]" level="application" />
53
54
  <orderEntry type="library" scope="PROVIDED" name="rubocop-rails (v2.12.4, rbenv: 3.0.2) [gem]" level="application" />
@@ -58,6 +59,7 @@
58
59
  <orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.12.3, rbenv: 3.0.2) [gem]" level="application" />
59
60
  <orderEntry type="library" scope="PROVIDED" name="simplecov_json_formatter (v0.1.3, rbenv: 3.0.2) [gem]" level="application" />
60
61
  <orderEntry type="library" scope="PROVIDED" name="slack-notifier (v2.4.0, rbenv: 3.0.2) [gem]" level="application" />
62
+ <orderEntry type="library" scope="PROVIDED" name="sqlite3 (v1.4.2, rbenv: 3.0.2) [gem]" level="application" />
61
63
  <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.4, rbenv: 3.0.2) [gem]" level="application" />
62
64
  <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.1.0, rbenv: 3.0.2) [gem]" level="application" />
63
65
  <orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.5.1, rbenv: 3.0.2) [gem]" level="application" />
@@ -66,21 +68,21 @@
66
68
  <option name="myRootTask">
67
69
  <RakeTaskImpl id="rake">
68
70
  <subtasks>
69
- <RakeTaskImpl description="Build moca_rlibs-0.0.3.gem into the pkg directory" fullCommand="build" id="build" />
71
+ <RakeTaskImpl description="Build moca_rlibs-0.0.4.gem into the pkg directory" fullCommand="build" id="build" />
70
72
  <RakeTaskImpl id="build">
71
73
  <subtasks>
72
- <RakeTaskImpl description="Generate SHA512 checksum if moca_rlibs-0.0.3.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
74
+ <RakeTaskImpl description="Generate SHA512 checksum if moca_rlibs-0.0.4.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
73
75
  </subtasks>
74
76
  </RakeTaskImpl>
75
77
  <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
76
78
  <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
77
- <RakeTaskImpl description="Build and install moca_rlibs-0.0.3.gem into system gems" fullCommand="install" id="install" />
79
+ <RakeTaskImpl description="Build and install moca_rlibs-0.0.4.gem into system gems" fullCommand="install" id="install" />
78
80
  <RakeTaskImpl id="install">
79
81
  <subtasks>
80
- <RakeTaskImpl description="Build and install moca_rlibs-0.0.3.gem into system gems without network access" fullCommand="install:local" id="local" />
82
+ <RakeTaskImpl description="Build and install moca_rlibs-0.0.4.gem into system gems without network access" fullCommand="install:local" id="local" />
81
83
  </subtasks>
82
84
  </RakeTaskImpl>
83
- <RakeTaskImpl description="Create tag v0.0.3 and build and push moca_rlibs-0.0.3.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
85
+ <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
86
  <RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
85
87
  <RakeTaskImpl description="" fullCommand="default" id="default" />
86
88
  <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)
4
+ moca_rlibs (0.0.5)
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.2.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)
@@ -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.22.3)
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)
@@ -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,59 @@ 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
+
21
74
  ## Grapeカスタムバリデーション
22
75
  メールアドレスのフォーマットチェック(簡易チェック)
23
76
  ```ruby
@@ -112,8 +165,7 @@ params do
112
165
  requires :text, type: String, only_alpha_numeric: true
113
166
  end
114
167
  ```
115
- 出力可能なアスキー文字しか含まれないこと
116
- (半角英数字、半角スペース、一部の表示可能な記号)
168
+ 出力可能なアスキー文字しか含まれないこと(半角英数字、一部の表示可能な記号)
117
169
  ```ruby
118
170
  params do
119
171
  requires :text, type: String, only_printable: true
@@ -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[attribute] << '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[attribute] << '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[attribute] << '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[attribute] << '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[attribute] << 'contain invalid characters (only printable ascii characters)'
16
+ end
17
+ end
18
+ 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?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MocaRlibs
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
data/lib/moca_rlibs.rb CHANGED
@@ -31,6 +31,11 @@ require_relative 'moca_rlibs/grape_errors/retry_required'
31
31
  require_relative 'moca_rlibs/grape_errors/service_unavailable'
32
32
  require_relative 'moca_rlibs/grape_errors/too_many_requests'
33
33
  require_relative 'moca_rlibs/grape_errors/unauthorized'
34
+ require_relative 'moca_rlibs/active_model_validators/only_alpha'
35
+ require_relative 'moca_rlibs/active_model_validators/only_alpha_numeric'
36
+ require_relative 'moca_rlibs/active_model_validators/only_ascii'
37
+ require_relative 'moca_rlibs/active_model_validators/only_numbers'
38
+ require_relative 'moca_rlibs/active_model_validators/only_printable'
34
39
 
35
40
  require 'active_model'
36
41
  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
4
+ version: 0.0.5
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-14 00:00:00.000000000 Z
11
+ date: 2021-11-30 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,11 @@ files:
249
277
  - buildspec.yml
250
278
  - docker/scripts/test.sh
251
279
  - lib/moca_rlibs.rb
280
+ - lib/moca_rlibs/active_model_validators/only_alpha.rb
281
+ - lib/moca_rlibs/active_model_validators/only_alpha_numeric.rb
282
+ - lib/moca_rlibs/active_model_validators/only_ascii.rb
283
+ - lib/moca_rlibs/active_model_validators/only_numbers.rb
284
+ - lib/moca_rlibs/active_model_validators/only_printable.rb
252
285
  - lib/moca_rlibs/codebuild.rb
253
286
  - lib/moca_rlibs/docker.rb
254
287
  - lib/moca_rlibs/grape_errors/bad_gateway.rb
@@ -285,9 +318,7 @@ homepage: https://github.com/mocaberos/rlibs
285
318
  licenses:
286
319
  - MIT
287
320
  metadata:
288
- homepage_uri: https://github.com/mocaberos/rlibs
289
- source_code_uri: https://github.com/mocaberos/rlibs
290
- changelog_uri: https://github.com/mocaberos/rlibs/blob/master/CHANGELOG.md
321
+ rubygems_mfa_required: 'true'
291
322
  post_install_message:
292
323
  rdoc_options: []
293
324
  require_paths: