phc_string_format 0.3.3 → 0.3.8
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 +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/.reek.yml +1 -8
- data/.rubocop.yml +1 -9
- data/.simplecov +4 -0
- data/.travis.yml +6 -2
- data/Gemfile +2 -0
- data/Gemfile.lock +49 -36
- data/README.md +4 -3
- data/lib/phc_string_format.rb +3 -2
- data/lib/phc_string_format/formatter.rb +1 -1
- data/lib/phc_string_format/phc_string.rb +40 -51
- data/lib/phc_string_format/validations.rb +34 -0
- data/lib/phc_string_format/version.rb +1 -1
- data/phc_string_format.gemspec +2 -2
- metadata +14 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 679957901160f40d7a114d76d447b4c347627108c99f3d7a77039f98ae8775f1
|
|
4
|
+
data.tar.gz: 2fc8ebd4e7043b97769999e92b433e06faab04e3a4aef4d5ff20f9631be2b995
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b8eecd0da8bbbd17de007880bc13f6101e07ba59095a4946ca1e41cbfe1f8fb7c77257a69334329b8d941f17d11d99564b6ad8829c0f7a5444d84cd94246fe84
|
|
7
|
+
data.tar.gz: bdde19da37640bf9ab41bdcc8f1af6f463148d838eb101cfbfc9c0eaa466cf3b12f791df86ec3c0536fb7fc6fb179a242c8ba056df7f6cd6232f6ca9875ff57d
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: Ruby
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ master ]
|
|
13
|
+
pull_request:
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
test:
|
|
17
|
+
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
strategy:
|
|
20
|
+
matrix:
|
|
21
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v2
|
|
25
|
+
- name: Set up Ruby
|
|
26
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
|
27
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
|
28
|
+
# uses: ruby/setup-ruby@v1
|
|
29
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
|
30
|
+
with:
|
|
31
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
32
|
+
bundler-cache: false # runs 'bundle install' and caches installed gems automatically
|
|
33
|
+
- run: bundle install --jobs 4
|
|
34
|
+
- name: Run tests
|
|
35
|
+
run: bundle exec rake
|
data/.reek.yml
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
detectors:
|
|
3
3
|
|
|
4
|
-
FeatureEnvy:
|
|
5
|
-
exclude:
|
|
6
|
-
- 'PhcStringFormat::PhcString#parse_params'
|
|
7
|
-
|
|
8
4
|
LongParameterList:
|
|
9
5
|
max_params: 6
|
|
10
|
-
overrides:
|
|
11
|
-
initialize:
|
|
12
|
-
max_params: 6
|
|
13
6
|
|
|
14
7
|
TooManyStatements:
|
|
15
8
|
max_statements: 10
|
|
16
9
|
|
|
17
10
|
TooManyInstanceVariables:
|
|
18
|
-
max_instance_variables:
|
|
11
|
+
max_instance_variables: 5
|
|
19
12
|
|
|
20
13
|
UncommunicativeModuleName:
|
|
21
14
|
accept:
|
data/.rubocop.yml
CHANGED
|
@@ -9,17 +9,12 @@ AllCops:
|
|
|
9
9
|
- '*.gemspec'
|
|
10
10
|
- Rakefile
|
|
11
11
|
|
|
12
|
-
Metrics/AbcSize:
|
|
13
|
-
Max: 20
|
|
14
|
-
|
|
15
12
|
Metrics/BlockLength:
|
|
16
13
|
Exclude:
|
|
17
14
|
- 'spec/**/*'
|
|
18
|
-
Metrics/ClassLength:
|
|
19
|
-
Max: 120
|
|
20
15
|
|
|
21
16
|
Metrics/CyclomaticComplexity:
|
|
22
|
-
Max:
|
|
17
|
+
Max: 7
|
|
23
18
|
|
|
24
19
|
Metrics/LineLength:
|
|
25
20
|
Max: 110
|
|
@@ -29,6 +24,3 @@ Metrics/MethodLength:
|
|
|
29
24
|
|
|
30
25
|
Metrics/ParameterLists:
|
|
31
26
|
Max: 6
|
|
32
|
-
|
|
33
|
-
Metrics/PerceivedComplexity:
|
|
34
|
-
Max: 10
|
data/.simplecov
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
|
@@ -7,3 +7,5 @@ gemspec
|
|
|
7
7
|
|
|
8
8
|
gem "rubocop", "~> 0.58.2", require: false, :groups => [:development, :test]
|
|
9
9
|
gem "reek", "~> 5.0", require: false, :groups => [:development, :test]
|
|
10
|
+
gem 'simplecov', '>= 0.16.1', require: false, group: :test
|
|
11
|
+
gem 'codacy-coverage', '>= 1.1.8', require: false, group: :test
|
data/Gemfile.lock
CHANGED
|
@@ -1,60 +1,65 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
phc_string_format (0.3.
|
|
4
|
+
phc_string_format (0.3.8)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
ast (2.4.
|
|
9
|
+
ast (2.4.2)
|
|
10
10
|
axiom-types (0.1.1)
|
|
11
11
|
descendants_tracker (~> 0.0.4)
|
|
12
12
|
ice_nine (~> 0.11.0)
|
|
13
13
|
thread_safe (~> 0.3, >= 0.3.1)
|
|
14
|
-
byebug (
|
|
14
|
+
byebug (11.1.3)
|
|
15
|
+
codacy-coverage (2.2.1)
|
|
16
|
+
simplecov
|
|
15
17
|
codeclimate-engine-rb (0.4.1)
|
|
16
18
|
virtus (~> 1.0)
|
|
17
|
-
coderay (1.1.
|
|
19
|
+
coderay (1.1.3)
|
|
18
20
|
coercible (1.0.0)
|
|
19
21
|
descendants_tracker (~> 0.0.1)
|
|
20
22
|
descendants_tracker (0.0.4)
|
|
21
23
|
thread_safe (~> 0.3, >= 0.3.1)
|
|
22
|
-
diff-lcs (1.
|
|
24
|
+
diff-lcs (1.4.4)
|
|
25
|
+
docile (1.3.5)
|
|
23
26
|
equalizer (0.0.11)
|
|
24
27
|
ice_nine (0.11.2)
|
|
25
|
-
jaro_winkler (1.5.
|
|
28
|
+
jaro_winkler (1.5.4)
|
|
26
29
|
kwalify (0.7.2)
|
|
27
|
-
method_source (0.
|
|
28
|
-
parallel (1.
|
|
29
|
-
parser (2.
|
|
30
|
-
ast (~> 2.4.
|
|
31
|
-
powerpack (0.1.
|
|
32
|
-
pry (0.
|
|
33
|
-
coderay (~> 1.1
|
|
34
|
-
method_source (~>
|
|
35
|
-
pry-byebug (3.
|
|
36
|
-
byebug (~>
|
|
37
|
-
pry (~> 0.
|
|
30
|
+
method_source (1.0.0)
|
|
31
|
+
parallel (1.20.1)
|
|
32
|
+
parser (2.7.2.0)
|
|
33
|
+
ast (~> 2.4.1)
|
|
34
|
+
powerpack (0.1.3)
|
|
35
|
+
pry (0.13.1)
|
|
36
|
+
coderay (~> 1.1)
|
|
37
|
+
method_source (~> 1.0)
|
|
38
|
+
pry-byebug (3.9.0)
|
|
39
|
+
byebug (~> 11.0)
|
|
40
|
+
pry (~> 0.13.0)
|
|
41
|
+
psych (3.1.0)
|
|
38
42
|
rainbow (3.0.0)
|
|
39
|
-
rake (
|
|
40
|
-
reek (5.0
|
|
43
|
+
rake (13.0.3)
|
|
44
|
+
reek (5.6.0)
|
|
41
45
|
codeclimate-engine-rb (~> 0.4.0)
|
|
42
46
|
kwalify (~> 0.7.0)
|
|
43
|
-
parser (>= 2.5.0.0, < 2.
|
|
47
|
+
parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
|
|
48
|
+
psych (~> 3.1.0)
|
|
44
49
|
rainbow (>= 2.0, < 4.0)
|
|
45
|
-
rspec (3.
|
|
46
|
-
rspec-core (~> 3.
|
|
47
|
-
rspec-expectations (~> 3.
|
|
48
|
-
rspec-mocks (~> 3.
|
|
49
|
-
rspec-core (3.
|
|
50
|
-
rspec-support (~> 3.
|
|
51
|
-
rspec-expectations (3.
|
|
50
|
+
rspec (3.10.0)
|
|
51
|
+
rspec-core (~> 3.10.0)
|
|
52
|
+
rspec-expectations (~> 3.10.0)
|
|
53
|
+
rspec-mocks (~> 3.10.0)
|
|
54
|
+
rspec-core (3.10.1)
|
|
55
|
+
rspec-support (~> 3.10.0)
|
|
56
|
+
rspec-expectations (3.10.1)
|
|
52
57
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
53
|
-
rspec-support (~> 3.
|
|
54
|
-
rspec-mocks (3.
|
|
58
|
+
rspec-support (~> 3.10.0)
|
|
59
|
+
rspec-mocks (3.10.2)
|
|
55
60
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
56
|
-
rspec-support (~> 3.
|
|
57
|
-
rspec-support (3.
|
|
61
|
+
rspec-support (~> 3.10.0)
|
|
62
|
+
rspec-support (3.10.2)
|
|
58
63
|
rubocop (0.58.2)
|
|
59
64
|
jaro_winkler (~> 1.5.1)
|
|
60
65
|
parallel (~> 1.10)
|
|
@@ -63,9 +68,15 @@ GEM
|
|
|
63
68
|
rainbow (>= 2.2.2, < 4.0)
|
|
64
69
|
ruby-progressbar (~> 1.7)
|
|
65
70
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
66
|
-
ruby-progressbar (1.
|
|
71
|
+
ruby-progressbar (1.11.0)
|
|
72
|
+
simplecov (0.21.2)
|
|
73
|
+
docile (~> 1.1)
|
|
74
|
+
simplecov-html (~> 0.11)
|
|
75
|
+
simplecov_json_formatter (~> 0.1)
|
|
76
|
+
simplecov-html (0.12.3)
|
|
77
|
+
simplecov_json_formatter (0.1.2)
|
|
67
78
|
thread_safe (0.3.6)
|
|
68
|
-
unicode-display_width (1.
|
|
79
|
+
unicode-display_width (1.7.0)
|
|
69
80
|
virtus (1.0.5)
|
|
70
81
|
axiom-types (~> 0.1)
|
|
71
82
|
coercible (~> 1.0)
|
|
@@ -76,13 +87,15 @@ PLATFORMS
|
|
|
76
87
|
ruby
|
|
77
88
|
|
|
78
89
|
DEPENDENCIES
|
|
79
|
-
bundler (~>
|
|
90
|
+
bundler (~> 2)
|
|
91
|
+
codacy-coverage (>= 1.1.8)
|
|
80
92
|
phc_string_format!
|
|
81
93
|
pry-byebug (~> 3.6)
|
|
82
|
-
rake (~>
|
|
94
|
+
rake (~> 13.0)
|
|
83
95
|
reek (~> 5.0)
|
|
84
96
|
rspec (~> 3.0)
|
|
85
97
|
rubocop (~> 0.58.2)
|
|
98
|
+
simplecov (>= 0.16.1)
|
|
86
99
|
|
|
87
100
|
BUNDLED WITH
|
|
88
|
-
|
|
101
|
+
2.0.1
|
data/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://travis-ci.org/naokikimura/phc_string_format)
|
|
5
5
|
[](https://snyk.io/test/github/naokikimura/phc_string_format?targetFile=Gemfile.lock)
|
|
6
6
|
[](https://app.codacy.com/app/naokikimura/phc_string_format?utm_source=github.com&utm_medium=referral&utm_content=naokikimura/phc_string_format&utm_campaign=badger)
|
|
7
|
+
[](https://www.codacy.com/app/naokikimura/phc_string_format?utm_source=github.com&utm_medium=referral&utm_content=naokikimura/phc_string_format&utm_campaign=Badge_Coverage)
|
|
7
8
|
|
|
8
9
|
PHC string format implemented by Ruby
|
|
9
10
|
|
|
@@ -31,13 +32,13 @@ require 'phc_string_format'
|
|
|
31
32
|
encrypted_password = '$argon2i$v=19$m=4096,t=3,p=1$IfH5R3O3r3501DfGnGr2rw$DfQ8Hv9R2eF2uBs1dR99IGjVjDl/rpkJIkaNyZ1g3pk'
|
|
32
33
|
|
|
33
34
|
# parse
|
|
34
|
-
|
|
35
|
+
phc_string_args = PhcStringFormat::Formatter.parse(encrypted_password)
|
|
35
36
|
# => {:id=>"argon2i", :version=>19, :params=>{"m"=>4096, "t"=>3, "p"=>1}, :salt=>"!\xF1\xF9Gs\xB7\xAF~t\xD47\xC6\x9Cj\xF6\xAF", :hash=>"\r\xF4<\x1E\xFFQ\xD9\xE1v\xB8\e5u\x1F} h\xD5\x8C9\x7F\xAE\x99\t\"F\x8D\xC9\x9D`\xDE\x99"}
|
|
36
37
|
|
|
37
38
|
# format
|
|
38
|
-
password_hash = PhcStringFormat::Formatter.format(
|
|
39
|
+
password_hash = PhcStringFormat::Formatter.format(phc_string_args)
|
|
39
40
|
|
|
40
|
-
password_hash ==
|
|
41
|
+
password_hash == encrypted_password
|
|
41
42
|
```
|
|
42
43
|
|
|
43
44
|
## Development
|
data/lib/phc_string_format.rb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
require 'phc_string_format/b64'
|
|
2
|
-
require 'phc_string_format/formatter'
|
|
3
|
-
require 'phc_string_format/phc_string'
|
|
4
2
|
require 'phc_string_format/version'
|
|
3
|
+
require 'phc_string_format/validations'
|
|
4
|
+
require 'phc_string_format/phc_string'
|
|
5
|
+
require 'phc_string_format/formatter'
|
|
5
6
|
|
|
6
7
|
#
|
|
7
8
|
# PHC string format implemented by Ruby
|
|
@@ -3,55 +3,39 @@ module PhcStringFormat
|
|
|
3
3
|
# Parser for parsing PHC-string-format.
|
|
4
4
|
#
|
|
5
5
|
class PhcString
|
|
6
|
-
|
|
7
|
-
@validators ||= []
|
|
8
|
-
@validators << lambda { |object|
|
|
9
|
-
value = object.instance_variable_get(name)
|
|
10
|
-
return if options[:allow_nil] && !value
|
|
11
|
-
regex = options.dig(:format, :with)
|
|
12
|
-
raise ArgumentError, options[:message] unless !regex || value =~ regex
|
|
13
|
-
}
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def self.validate(name, **options)
|
|
17
|
-
@validators ||= []
|
|
18
|
-
@validators << ->(object) { raise ArgumentError, options[:message] unless object.send(name) }
|
|
19
|
-
end
|
|
6
|
+
include Validations
|
|
20
7
|
|
|
21
|
-
def self.
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
def self.parse(string)
|
|
9
|
+
string ||= ''
|
|
10
|
+
PhcString.new(*split(string))
|
|
11
|
+
rescue StandardError => exception
|
|
12
|
+
raise ParseError, exception.message
|
|
24
13
|
end
|
|
25
14
|
|
|
26
|
-
private_class_method :validates, :validate
|
|
27
|
-
|
|
28
15
|
# :reek:DuplicateMethodCall { allow_calls: ['elements.shift', 'elements.first'] }
|
|
29
|
-
def self.
|
|
30
|
-
string ||= ''
|
|
16
|
+
def self.split(string)
|
|
31
17
|
elements = string.split(/\$/, 6)
|
|
32
18
|
elements.shift
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
rescue ArgumentError
|
|
41
|
-
raise ParseError
|
|
42
|
-
end
|
|
19
|
+
[
|
|
20
|
+
elements.shift,
|
|
21
|
+
(elements.shift if (elements.first || '').start_with?('v=')),
|
|
22
|
+
(elements.shift if (elements.first || '').include?('=')),
|
|
23
|
+
elements.shift,
|
|
24
|
+
elements.shift
|
|
25
|
+
]
|
|
43
26
|
end
|
|
44
27
|
|
|
45
28
|
def self.create(id:, version: nil, params: nil, salt: nil, hash: nil, hint: {})
|
|
46
|
-
PhcString.new
|
|
29
|
+
PhcString.new \
|
|
47
30
|
id,
|
|
48
|
-
(
|
|
49
|
-
(
|
|
31
|
+
(Parameters.to_s(v: version) if version),
|
|
32
|
+
(Parameters.to_s(params) if params),
|
|
50
33
|
hint.dig(:salt, :encoding) == '7bit' ? salt : B64.encode(salt),
|
|
51
34
|
B64.encode(hash)
|
|
52
|
-
)
|
|
53
35
|
end
|
|
54
36
|
|
|
37
|
+
private_class_method :split
|
|
38
|
+
|
|
55
39
|
validates :@id, message: 'id is non-compliant', format: { with: /\A[a-z0-9-]{1,32}\z/ }
|
|
56
40
|
validates \
|
|
57
41
|
:@version_string,
|
|
@@ -63,12 +47,12 @@ module PhcStringFormat
|
|
|
63
47
|
:@encoded_salt,
|
|
64
48
|
message: 'encoded salt is non-compliant',
|
|
65
49
|
allow_nil: true,
|
|
66
|
-
format: { with: %r{\A[a-zA-Z0-9/+.-]
|
|
50
|
+
format: { with: %r{\A[a-zA-Z0-9/+.-]*\z} }
|
|
67
51
|
validates \
|
|
68
52
|
:@encoded_hash,
|
|
69
53
|
message: 'encoded hash is non-compliant',
|
|
70
54
|
allow_nil: true,
|
|
71
|
-
format: { with: %r{\A[a-zA-Z0-9/+]
|
|
55
|
+
format: { with: %r{\A[a-zA-Z0-9/+]*\z} }
|
|
72
56
|
validate :validate_salt_and_hash, message: 'hash needs salt'
|
|
73
57
|
|
|
74
58
|
def initialize(id, version_string, params_string, encoded_salt, encoded_hash)
|
|
@@ -88,15 +72,15 @@ module PhcStringFormat
|
|
|
88
72
|
@params_string,
|
|
89
73
|
@encoded_salt,
|
|
90
74
|
@encoded_hash
|
|
91
|
-
].
|
|
75
|
+
].compact.join('$')
|
|
92
76
|
end
|
|
93
77
|
|
|
94
78
|
def to_h(pick: nil, hint: {})
|
|
95
79
|
pick ||= %i[id version params salt hash]
|
|
96
80
|
{
|
|
97
81
|
id: (@id if pick.include?(:id)),
|
|
98
|
-
version: (
|
|
99
|
-
params: (
|
|
82
|
+
version: (Parameters.to_h(@version_string)['v'] if pick.include?(:version)),
|
|
83
|
+
params: (Parameters.to_h(@params_string) if pick.include?(:params)),
|
|
100
84
|
salt:
|
|
101
85
|
if pick.include?(:salt)
|
|
102
86
|
hint.dig(:salt, :encoding) == '7bit' ? @encoded_salt : B64.decode(@encoded_salt)
|
|
@@ -118,21 +102,26 @@ module PhcStringFormat
|
|
|
118
102
|
end
|
|
119
103
|
|
|
120
104
|
def validate_salt_and_hash
|
|
121
|
-
|
|
105
|
+
@encoded_salt || !@encoded_hash
|
|
122
106
|
end
|
|
123
107
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
108
|
+
#
|
|
109
|
+
# PHC string parameters
|
|
110
|
+
#
|
|
111
|
+
module Parameters
|
|
112
|
+
def self.to_s(params)
|
|
113
|
+
params ||= {}
|
|
114
|
+
params.map { |param| param.join '=' }.join(',')
|
|
115
|
+
end
|
|
127
116
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
def self.to_h(params_string)
|
|
118
|
+
params_string ||= ''
|
|
119
|
+
params_string
|
|
120
|
+
.split(/,/)
|
|
121
|
+
.map { |param| param.split '=' }
|
|
122
|
+
.map { |name, value| [name, value =~ /\A-?\d+(.\d+)?\Z/ ? value.to_i : value] }
|
|
123
|
+
.to_h
|
|
133
124
|
end
|
|
134
|
-
params_string ||= ''
|
|
135
|
-
params_string.split(/,/).map(&mapper).each_with_object({}, &reducer)
|
|
136
125
|
end
|
|
137
126
|
end
|
|
138
127
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module PhcStringFormat
|
|
2
|
+
#
|
|
3
|
+
# Provides a validation framework to your objects.
|
|
4
|
+
#
|
|
5
|
+
module Validations
|
|
6
|
+
def self.included(klass)
|
|
7
|
+
klass.extend ClassMethods
|
|
8
|
+
end
|
|
9
|
+
#
|
|
10
|
+
# class methods
|
|
11
|
+
#
|
|
12
|
+
module ClassMethods
|
|
13
|
+
def validates(name, **options)
|
|
14
|
+
@validators ||= []
|
|
15
|
+
@validators << lambda { |object|
|
|
16
|
+
value = object.instance_variable_get(name)
|
|
17
|
+
return if options[:allow_nil] && !value
|
|
18
|
+
regex = options.dig(:format, :with)
|
|
19
|
+
raise ArgumentError, options[:message] unless !regex || value =~ regex
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def validate(name, **options)
|
|
24
|
+
@validators ||= []
|
|
25
|
+
@validators << ->(object) { raise ArgumentError, options[:message] unless object.send(name) }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def do_validate(that)
|
|
29
|
+
@validators.each { |validator| validator.call(that) }
|
|
30
|
+
that
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/phc_string_format.gemspec
CHANGED
|
@@ -27,8 +27,8 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
28
|
spec.require_paths = ["lib"]
|
|
29
29
|
|
|
30
|
-
spec.add_development_dependency "bundler", "~>
|
|
31
|
-
spec.add_development_dependency "rake", "~>
|
|
30
|
+
spec.add_development_dependency "bundler", "~> 2"
|
|
31
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
32
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
33
33
|
spec.add_development_dependency "pry-byebug", "~> 3.6"
|
|
34
34
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: phc_string_format
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- naokikimura
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-02-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -16,28 +16,28 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '2'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '2'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '13.0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '13.0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rspec
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,17 +66,19 @@ dependencies:
|
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '3.6'
|
|
69
|
-
description:
|
|
69
|
+
description:
|
|
70
70
|
email:
|
|
71
71
|
- n.kimura.cap@gmail.com
|
|
72
72
|
executables: []
|
|
73
73
|
extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
|
75
75
|
files:
|
|
76
|
+
- ".github/workflows/ruby.yml"
|
|
76
77
|
- ".gitignore"
|
|
77
78
|
- ".reek.yml"
|
|
78
79
|
- ".rspec"
|
|
79
80
|
- ".rubocop.yml"
|
|
81
|
+
- ".simplecov"
|
|
80
82
|
- ".travis.yml"
|
|
81
83
|
- CODE_OF_CONDUCT.md
|
|
82
84
|
- Gemfile
|
|
@@ -90,6 +92,7 @@ files:
|
|
|
90
92
|
- lib/phc_string_format/b64.rb
|
|
91
93
|
- lib/phc_string_format/formatter.rb
|
|
92
94
|
- lib/phc_string_format/phc_string.rb
|
|
95
|
+
- lib/phc_string_format/validations.rb
|
|
93
96
|
- lib/phc_string_format/version.rb
|
|
94
97
|
- phc_string_format.gemspec
|
|
95
98
|
homepage: https://github.com/naokikimura/phc_string_format
|
|
@@ -98,7 +101,7 @@ licenses:
|
|
|
98
101
|
metadata:
|
|
99
102
|
bug_tracker_uri: https://github.com/naokikimura/phc_string_format/issues
|
|
100
103
|
source_code_uri: https://github.com/naokikimura/phc_string_format.git
|
|
101
|
-
post_install_message:
|
|
104
|
+
post_install_message:
|
|
102
105
|
rdoc_options: []
|
|
103
106
|
require_paths:
|
|
104
107
|
- lib
|
|
@@ -113,9 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
113
116
|
- !ruby/object:Gem::Version
|
|
114
117
|
version: '0'
|
|
115
118
|
requirements: []
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
signing_key:
|
|
119
|
+
rubygems_version: 3.0.3
|
|
120
|
+
signing_key:
|
|
119
121
|
specification_version: 4
|
|
120
122
|
summary: PHC string format implemented by Ruby.
|
|
121
123
|
test_files: []
|