phc_string_format 0.3.4 → 0.3.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 74aad184bd05ef181197a6511faf147117419a36
4
- data.tar.gz: 67d273fc6645159868754577049e5c6161454831
2
+ SHA256:
3
+ metadata.gz: bb2f0d0c00976c78f68dfc2ebdaa2fa87bbe930aecd1a97a29d41352f6f03bb2
4
+ data.tar.gz: 98d1aa8ababe727401fe90b8235f645598037c864d23fc67b9992c6adc3aeeb5
5
5
  SHA512:
6
- metadata.gz: 727d3a0d2e0d0803f0331b897175cd79e36f17feccee6e0b91a02b0ebef6e9e75b083472b527b5ff04939c135696a620fae06b22159222b775d386c69c27771b
7
- data.tar.gz: f1a8cf1788ace3f1ed3c4ad777492d53daf16782f88f4c539b8c3752895c0172dd8673d247cd046d6b74fd2e2052f6f8a5954f891f3ac3745c5a54457b8594c9
6
+ metadata.gz: d237ce6fc74598654b30c18b16688e15407d89e3df3d051282a77d4a8ab9be1d6f06da53927083dbf89cbdb238896004f2cbc20e83bbbd1b4206713dcfafb80b
7
+ data.tar.gz: 3c81d00427397be5fe6357e9478eda86864bb35388430a97d86e83839d92409bc29b72c0f1a2bd3524249e2b7591a014f4cdd995abb4c0bba3162009da115f26
@@ -9,26 +9,18 @@ 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: 10
17
+ Max: 7
23
18
 
24
19
  Metrics/LineLength:
25
- Max: 110
20
+ Max: 110
26
21
 
27
22
  Metrics/MethodLength:
28
23
  Max: 15
29
24
 
30
25
  Metrics/ParameterLists:
31
26
  Max: 6
32
-
33
- Metrics/PerceivedComplexity:
34
- Max: 10
@@ -0,0 +1,4 @@
1
+ SimpleCov.start do
2
+ add_filter '/tmp/'
3
+ add_filter '/spec/'
4
+ end
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', require: false, group: :test
11
+ gem 'codacy-coverage', require: false, group: :test
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phc_string_format (0.3.4)
4
+ phc_string_format (0.3.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,6 +12,8 @@ GEM
12
12
  ice_nine (~> 0.11.0)
13
13
  thread_safe (~> 0.3, >= 0.3.1)
14
14
  byebug (10.0.2)
15
+ codacy-coverage (1.1.8)
16
+ simplecov
15
17
  codeclimate-engine-rb (0.4.1)
16
18
  virtus (~> 1.0)
17
19
  coderay (1.1.2)
@@ -20,9 +22,11 @@ GEM
20
22
  descendants_tracker (0.0.4)
21
23
  thread_safe (~> 0.3, >= 0.3.1)
22
24
  diff-lcs (1.3)
25
+ docile (1.3.1)
23
26
  equalizer (0.0.11)
24
27
  ice_nine (0.11.2)
25
28
  jaro_winkler (1.5.1)
29
+ json (2.1.0)
26
30
  kwalify (0.7.2)
27
31
  method_source (0.9.0)
28
32
  parallel (1.12.1)
@@ -64,6 +68,11 @@ GEM
64
68
  ruby-progressbar (~> 1.7)
65
69
  unicode-display_width (~> 1.0, >= 1.0.1)
66
70
  ruby-progressbar (1.9.0)
71
+ simplecov (0.16.1)
72
+ docile (~> 1.1)
73
+ json (>= 1.8, < 3)
74
+ simplecov-html (~> 0.10.0)
75
+ simplecov-html (0.10.2)
67
76
  thread_safe (0.3.6)
68
77
  unicode-display_width (1.4.0)
69
78
  virtus (1.0.5)
@@ -77,12 +86,14 @@ PLATFORMS
77
86
 
78
87
  DEPENDENCIES
79
88
  bundler (~> 1.16)
89
+ codacy-coverage
80
90
  phc_string_format!
81
91
  pry-byebug (~> 3.6)
82
92
  rake (~> 10.0)
83
93
  reek (~> 5.0)
84
94
  rspec (~> 3.0)
85
95
  rubocop (~> 0.58.2)
96
+ simplecov
86
97
 
87
98
  BUNDLED WITH
88
99
  1.16.2
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
  [![Build Status](https://travis-ci.org/naokikimura/phc_string_format.svg?branch=master)](https://travis-ci.org/naokikimura/phc_string_format)
5
5
  [![Known Vulnerabilities](https://snyk.io/test/github/naokikimura/phc_string_format/badge.svg?targetFile=Gemfile.lock)](https://snyk.io/test/github/naokikimura/phc_string_format?targetFile=Gemfile.lock)
6
6
  [![Codacy Badge](https://api.codacy.com/project/badge/Grade/cbcb6fa3556447a4af16980f3cc6f1eb)](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
+ [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/26df342921414ee69b69f028cefe4f3b)](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
- phc_string_params = PhcStringFormat::Formatter.parse(encrypted_password)
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(phc_string_params)
39
+ password_hash = PhcStringFormat::Formatter.format(phc_string_args)
39
40
 
40
- password_hash == phc_string_format
41
+ password_hash == encrypted_password
41
42
  ```
42
43
 
43
44
  ## Development
@@ -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,25 +3,7 @@ module PhcStringFormat
3
3
  # Parser for parsing PHC-string-format.
4
4
  #
5
5
  class PhcString
6
- def self.validates(name, **options)
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
20
-
21
- def self.do_validate(that)
22
- @validators.each { |validator| validator.call(that) }
23
- that
24
- end
6
+ include Validations
25
7
 
26
8
  def self.parse(string)
27
9
  string ||= ''
@@ -53,7 +35,7 @@ module PhcStringFormat
53
35
  )
54
36
  end
55
37
 
56
- private_class_method :validates, :validate, :split
38
+ private_class_method :split
57
39
 
58
40
  validates :@id, message: 'id is non-compliant', format: { with: /\A[a-z0-9-]{1,32}\z/ }
59
41
  validates \
@@ -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
@@ -1,3 +1,3 @@
1
1
  module PhcStringFormat
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  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
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - naokikimura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-03 00:00:00.000000000 Z
11
+ date: 2018-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,6 +77,7 @@ files:
77
77
  - ".reek.yml"
78
78
  - ".rspec"
79
79
  - ".rubocop.yml"
80
+ - ".simplecov"
80
81
  - ".travis.yml"
81
82
  - CODE_OF_CONDUCT.md
82
83
  - Gemfile
@@ -90,6 +91,7 @@ files:
90
91
  - lib/phc_string_format/b64.rb
91
92
  - lib/phc_string_format/formatter.rb
92
93
  - lib/phc_string_format/phc_string.rb
94
+ - lib/phc_string_format/validations.rb
93
95
  - lib/phc_string_format/version.rb
94
96
  - phc_string_format.gemspec
95
97
  homepage: https://github.com/naokikimura/phc_string_format
@@ -114,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
116
  version: '0'
115
117
  requirements: []
116
118
  rubyforge_project:
117
- rubygems_version: 2.5.2.3
119
+ rubygems_version: 2.7.6
118
120
  signing_key:
119
121
  specification_version: 4
120
122
  summary: PHC string format implemented by Ruby.