salsify-gtin 0.2.0 → 0.2.1

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: 5f279583cc76509f46898df34d5b66a27a7454db60d5f9f7fe8f05e161afaf51
4
- data.tar.gz: b730b522cc2d9defbf1abbfc10d77658bc7a95dea0806f4481310dae2bca8ced
3
+ metadata.gz: bf85b1127e3fef3f0b0b68475014f14fe6fbe53af40d0af59f8e28e8925fbf17
4
+ data.tar.gz: 71ffc083ccd48af8d2872f5b6cb185fdea89f4faf29420f13eaa857603753cc6
5
5
  SHA512:
6
- metadata.gz: 6f29318ae9ae3fccc96a401a19f7b6125a2531dbeec40e6fcaa993f7e6c25a1fc38835c09809479108b9e961fccfa01b633d6a7a55043ed57e0c5c856f570d7e
7
- data.tar.gz: 10a357e7e16c526bd6278625699c73b035afdbc4542d605dc5fa371b48e11a68774a3799626740799978d1d6e803c47d37befea1e28e65da4888e21d5fbeb1e7
6
+ metadata.gz: 857e0fd70954caca95353b14963ed25983037027a6e0bc4e94d2c111b1409443f20e0284fd832b01804e0d383482d772add402daa74bc0c84df9950067626a79
7
+ data.tar.gz: 3317865cf3966e553d0b9783d5500131ed6aae374de7d3a9b86cbd45651d0ac7c03b08c03146ba8c46a6c41f7283e4f5b1bcd09b40cfda8e8f1b374f57130421
@@ -3,12 +3,16 @@ jobs:
3
3
  build:
4
4
  docker:
5
5
  - image: salsify/ruby_ci:2.5.1
6
- working_directory: ~/gtin
6
+ environment:
7
+ RACK_ENV: "test"
8
+ RAILS_ENV: "test"
9
+ CIRCLE_TEST_REPORTS: "test-results"
10
+ working_directory: ~/salsify-gtin
7
11
  steps:
8
12
  - checkout
9
13
  - restore_cache:
10
14
  keys:
11
- - v1-gems-ruby-2.5.1-{{ checksum "salsify-jira.gemspec" }}-{{ checksum "Gemfile.lock" }}
15
+ - v1-gems-ruby-2.5.1-{{ checksum "gtin.gemspec" }}-{{ checksum "Gemfile" }}
12
16
  - v1-gems-ruby-2.5.1-
13
17
  - run:
14
18
  name: Install Gems
@@ -18,7 +22,7 @@ jobs:
18
22
  bundle clean
19
23
  fi
20
24
  - save_cache:
21
- key: v1-gems-ruby-2.5.1-{{ checksum "salsify-jira.gemspec" }}-{{ checksum "Gemfile.lock" }}
25
+ key: v1-gems-ruby-2.5.1-{{ checksum "gtin.gemspec" }}-{{ checksum "Gemfile" }}
22
26
  paths:
23
27
  - "vendor/bundle"
24
28
  - "gemfiles/vendor"
@@ -30,4 +34,4 @@ jobs:
30
34
  command: |
31
35
  bundle exec rspec --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/junit.xml --format progress spec
32
36
  - store_test_results:
33
- path: 'test-results'
37
+ path: $CIRCLE_TEST_REPORTS
@@ -1,3 +1,5 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  inherit_gem:
2
4
  salsify_rubocop: conf/rubocop.yml
3
5
 
@@ -0,0 +1,20 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-02-12 14:05:52 -0500 using RuboCop version 0.52.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: AllowMultipleReturnValues.
12
+ Style/RedundantReturn:
13
+ Exclude:
14
+ - 'lib/gtin/gtin.rb'
15
+
16
+ # Offense count: 10
17
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
18
+ # URISchemes: http, https
19
+ Metrics/LineLength:
20
+ Max: 134
@@ -33,6 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'pry-byebug'
34
34
  spec.add_development_dependency 'rake', '~> 10.0'
35
35
  spec.add_development_dependency 'rspec', '~> 3.4'
36
-
36
+ spec.add_development_dependency 'rspec_junit_formatter', '0.2.2'
37
37
  spec.add_development_dependency 'salsify_rubocop', '~> 0.52.1'
38
38
  end
@@ -31,8 +31,13 @@ module GTIN
31
31
  end
32
32
 
33
33
  def standardize(id_type, value, validate_checksum: true)
34
- fail_on_invalid_checksum(id_type, value) if validate_checksum
35
34
  converter = get_converter(id_type, value.length)
35
+ if converter.nil?
36
+ raise GtinValidationError.new("#{id_type} standardization failed: no gtin converter for value with length #{value.length}")
37
+ end
38
+
39
+ fail_on_invalid_checksum(id_type, value) if validate_checksum
40
+
36
41
  send(converter.standardizer, value)
37
42
  end
38
43
 
@@ -41,7 +46,8 @@ module GTIN
41
46
  return converter if type_matcher.match?(id_type) && value_length == length
42
47
  end
43
48
 
44
- raise GtinValidationError.new("No gtin converter found for #{id_type} with length #{value_length}")
49
+ # rubocop warns about this, but it's needed because #each returns its owner
50
+ return nil
45
51
  end
46
52
 
47
53
  def standardize_gtin(gtin)
@@ -76,12 +82,18 @@ module GTIN
76
82
 
77
83
  def valid_checksum?(id_type, identifier)
78
84
  converter = get_converter(id_type, identifier.length)
85
+ return false if converter.nil?
86
+
79
87
  expected_checksum = send(converter.checksum_computer, identifier[0..-2])
80
88
  identifier[-1] == expected_checksum
81
89
  end
82
90
 
83
91
  def fail_on_invalid_checksum(id_type, identifier)
84
92
  converter = get_converter(id_type, identifier.length)
93
+ if converter.nil?
94
+ raise GtinValidationError.new("Invalid checksum: gtin converter not found for #{id_type} with length #{value.length}")
95
+ end
96
+
85
97
  expected_checksum = send(converter.checksum_computer, identifier[0..-2])
86
98
  actual_checksum = identifier[-1]
87
99
  return if actual_checksum == expected_checksum
@@ -1,3 +1,3 @@
1
1
  module GTIN
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salsify-gtin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salsify, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-08 00:00:00.000000000 Z
11
+ date: 2019-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec_junit_formatter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.2
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: salsify_rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +123,7 @@ files:
109
123
  - ".overcommit.yml"
110
124
  - ".rspec"
111
125
  - ".rubocop.yml"
126
+ - ".rubocop_todo.yml"
112
127
  - ".travis.yml"
113
128
  - CHANGELOG.md
114
129
  - Gemfile