issuer_response_codes 0.2.5 → 0.3.0

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
2
  SHA256:
3
- metadata.gz: 37ba4c8ea618ac92cad2812d33718b65dc667a9cd33c74f9022682490c6c262a
4
- data.tar.gz: ce06e7107a1138c0c681a78bf03e8336eaa5ef9745c58c9781dedf221e1b9c14
3
+ metadata.gz: 78eac7a89806d60339f0ef7f789ed08b60a6fb675e651e620cd51e3de49dbcfe
4
+ data.tar.gz: 6b48a34c1925e916cc67a6c29cc4857104e7e34081588f49035294024b383d8c
5
5
  SHA512:
6
- metadata.gz: fc4cc8e087f2c0b4d44a14de3cb4ba06b171880fe0a77ed65677fea7d8b26ebbb4a6ec3e53e55ca41ff3c71e131cc59c4f00a3f66356a97f24fd995bc098c5fd
7
- data.tar.gz: dde8649dc04e1243d070774403c28697b4e0cdd33ebbc8f8b37f8ed6cafbe16b134fdb9c38cc54c96863bcdc7b33c94357360d4b846ea8eae30973e8cee62454
6
+ metadata.gz: bce421e3c6b41c00929a3bd71756b28d4002707dbc4ff2bc65c284a2055fe548b5b855492d7dbfbffdc9651b2527f7d903d6c654bca7327556ca2792899226db
7
+ data.tar.gz: 73cc431569db42ccae5f0c899858af55eb04719964525f8b648c759fac085e2e5f23f2475ecce812c421ff1f833dcf20de28fb97412587f23be11533ba5b6593
@@ -0,0 +1,38 @@
1
+ name: CI Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ 'main' ]
6
+ pull_request:
7
+ branches: [ 'main' ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ env:
13
+ CI: true
14
+ strategy:
15
+ matrix:
16
+ ruby-version: ['3.0', '3.1', '3.2']
17
+ steps:
18
+ - name: Checkout code
19
+ uses: actions/checkout@v3
20
+ - name: Install Ruby and gems
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby-version }}
24
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
25
+ - name: Run unit tests
26
+ run: bundle exec rake test
27
+
28
+ lint:
29
+ runs-on: ubuntu-latest
30
+ steps:
31
+ - name: Checkout code
32
+ uses: actions/checkout@v3
33
+ - name: Install Ruby and gems
34
+ uses: ruby/setup-ruby@v1
35
+ with:
36
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
+ - name: Lint
38
+ run: bundle exec rubocop --parallel --color
data/.rubocop.yml CHANGED
@@ -1,78 +1,5 @@
1
- Style/StringLiterals:
2
- Enabled: false
3
-
4
- Style/SingleArgumentDig:
5
- Enabled: false
6
-
7
- Layout/LineLength:
8
- Enabled: false
9
-
10
- Style/Documentation:
11
- Enabled: false
12
-
13
- Style/ClassAndModuleChildren:
14
- Enabled: false
15
-
16
- Style/MethodCallWithArgsParentheses:
17
- Enabled: false
18
-
19
- Style/ModuleFunction:
20
- EnforcedStyle: 'extend_self'
21
-
22
- Style/MissingElse:
23
- Enabled: false
24
-
25
- Lint/NumberConversion:
26
- Enabled: false
27
-
28
- Lint/ConstantResolution:
29
- Enabled: false
30
-
31
- Style/RescueStandardError:
32
- Enabled: false
33
-
34
- Style/FormatStringToken:
35
- Enabled: false
36
-
37
- Style/FormatString:
38
- Enabled: false
39
-
40
- Style/DocumentationMethod:
41
- Enabled: false
42
-
43
- Style/Copyright:
44
- Enabled: false
45
-
46
- Style/StringHashKeys:
47
- Enabled: false
48
-
49
- Style/InlineComment:
50
- Enabled: false
51
-
52
- Layout/FirstHashElementLineBreak:
53
- Enabled: false
54
-
55
- Layout/FirstMethodArgumentLineBreak:
56
- Enabled: false
57
-
58
- Style/ConstantVisibility:
59
- Enabled: false
60
-
61
- Layout/FirstArrayElementLineBreak:
62
- Enabled: false
63
-
64
- Layout/MultilineMethodArgumentLineBreaks:
65
- Enabled: false
66
-
67
- Layout/MultilineAssignmentLayout:
68
- Enabled: false
69
-
70
- Bundler/GemComment:
71
- Enabled: false
1
+ inherit_gem:
2
+ rubocop-espago: rubocop.yml
72
3
 
73
4
  AllCops:
74
- EnabledByDefault: true
75
- Exclude:
76
- - 'bin/*'
77
- - 'spec/**/*'
78
- - 'test/**/*'
5
+ TargetRubyVersion: 3.0
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.2
1
+ 3.1.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+
9
+ ## [0.3.0]
10
+
11
+ [Diff](https://github.com/espago/issuer_response_codes/compare/v0.3.0...espago:issuer_response_codes:v0.2.5)
12
+
13
+ This release adds support for Ruby 3.1 and 3.2 and full translations for brand new languages: `:es, :fi, :fr, :hr, :it, :nl, :pt`.
data/Gemfile CHANGED
@@ -1,6 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in issuer_response_codes.gemspec
6
6
  gemspec
7
+
8
+ gem 'bundler', '~> 2.0' # library manager
9
+ gem 'debug', '~> 1.6.3' # debugger
10
+ gem 'minitest', '~> 5.0' # test framework
11
+ gem 'rake', '~> 12.0' # automation
12
+ gem 'rubocop', '~> 1.54' # linter
13
+ gem 'rubocop-espago', '~> 1.0' # linter config
14
+ gem 'solargraph', '~> 0.49' # language server
data/Gemfile.lock CHANGED
@@ -1,84 +1,97 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- issuer_response_codes (0.2.5)
4
+ issuer_response_codes (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
10
  backport (1.2.0)
11
- benchmark (0.1.1)
12
- bundler-audit (0.8.0)
13
- bundler (>= 1.2.0, < 3)
14
- thor (~> 1.0)
15
- byebug (11.1.3)
16
- diff-lcs (1.4.4)
11
+ benchmark (0.2.1)
12
+ debug (1.6.3)
13
+ irb (>= 1.3.6)
14
+ reline (>= 0.3.1)
15
+ diff-lcs (1.5.0)
17
16
  e2mmap (0.1.0)
18
- jaro_winkler (1.5.4)
19
- kramdown (2.3.1)
17
+ io-console (0.5.11)
18
+ irb (1.4.1)
19
+ reline (>= 0.3.0)
20
+ jaro_winkler (1.5.6)
21
+ json (2.6.3)
22
+ kramdown (2.4.0)
20
23
  rexml
21
24
  kramdown-parser-gfm (1.1.0)
22
25
  kramdown (~> 2.0)
23
- mini_portile2 (2.5.3)
24
- minitest (5.14.4)
25
- nokogiri (1.11.7)
26
- mini_portile2 (~> 2.5.0)
26
+ language_server-protocol (3.17.0.3)
27
+ mini_portile2 (2.8.4)
28
+ minitest (5.18.1)
29
+ nokogiri (1.15.3)
30
+ mini_portile2 (~> 2.8.2)
27
31
  racc (~> 1.4)
28
- parallel (1.20.1)
29
- parser (3.0.1.1)
32
+ parallel (1.23.0)
33
+ parser (3.2.2.3)
30
34
  ast (~> 2.4.1)
31
- racc (1.5.2)
32
- rainbow (3.0.0)
35
+ racc
36
+ racc (1.7.1)
37
+ rainbow (3.1.1)
33
38
  rake (12.3.3)
34
- regexp_parser (2.1.1)
35
- reverse_markdown (2.0.0)
39
+ rbs (2.8.4)
40
+ regexp_parser (2.8.1)
41
+ reline (0.3.1)
42
+ io-console (~> 0.5)
43
+ reverse_markdown (2.1.1)
36
44
  nokogiri
37
45
  rexml (3.2.5)
38
- rubocop (1.18.2)
46
+ rubocop (1.54.2)
47
+ json (~> 2.3)
48
+ language_server-protocol (>= 3.17.0)
39
49
  parallel (~> 1.10)
40
- parser (>= 3.0.0.0)
50
+ parser (>= 3.2.2.3)
41
51
  rainbow (>= 2.2.2, < 4.0)
42
52
  regexp_parser (>= 1.8, < 3.0)
43
- rexml
44
- rubocop-ast (>= 1.7.0, < 2.0)
53
+ rexml (>= 3.2.5, < 4.0)
54
+ rubocop-ast (>= 1.28.0, < 2.0)
45
55
  ruby-progressbar (~> 1.7)
46
- unicode-display_width (>= 1.4.0, < 3.0)
47
- rubocop-ast (1.7.0)
48
- parser (>= 3.0.1.1)
49
- ruby-progressbar (1.11.0)
50
- solargraph (0.42.3)
56
+ unicode-display_width (>= 2.4.0, < 3.0)
57
+ rubocop-ast (1.29.0)
58
+ parser (>= 3.2.1.0)
59
+ rubocop-espago (1.0.3)
60
+ rubocop
61
+ ruby-progressbar (1.13.0)
62
+ solargraph (0.49.0)
51
63
  backport (~> 1.2)
52
64
  benchmark
53
- bundler (>= 1.17.2)
65
+ bundler (~> 2.0)
54
66
  diff-lcs (~> 1.4)
55
67
  e2mmap
56
68
  jaro_winkler (~> 1.5)
57
69
  kramdown (~> 2.3)
58
70
  kramdown-parser-gfm (~> 1.1)
59
71
  parser (~> 3.0)
60
- reverse_markdown (>= 1.0.5, < 3)
61
- rubocop (>= 0.52)
72
+ rbs (~> 2.0)
73
+ reverse_markdown (~> 2.0)
74
+ rubocop (~> 1.38)
62
75
  thor (~> 1.0)
63
76
  tilt (~> 2.0)
64
77
  yard (~> 0.9, >= 0.9.24)
65
- thor (1.1.0)
66
- tilt (2.0.10)
67
- unicode-display_width (2.0.0)
68
- yard (0.9.26)
78
+ thor (1.2.2)
79
+ tilt (2.2.0)
80
+ unicode-display_width (2.4.2)
81
+ yard (0.9.34)
69
82
 
70
83
  PLATFORMS
71
84
  ruby
72
85
 
73
86
  DEPENDENCIES
74
- bundler
75
- bundler-audit
76
- byebug
87
+ bundler (~> 2.0)
88
+ debug (~> 1.6.3)
77
89
  issuer_response_codes!
78
90
  minitest (~> 5.0)
79
91
  rake (~> 12.0)
80
- rubocop
81
- solargraph
92
+ rubocop (~> 1.54)
93
+ rubocop-espago (~> 1.0)
94
+ solargraph (~> 0.49)
82
95
 
83
96
  BUNDLED WITH
84
- 2.1.4
97
+ 2.4.17
data/README.md CHANGED
@@ -4,12 +4,18 @@ This gem provides a quite comprehensive library of Issuer Response Code and 3D-S
4
4
  - Complete locales:
5
5
  - en
6
6
  - pl
7
+ - es
8
+ - fi
9
+ - fr
10
+ - hr
11
+ - it
12
+ - nl
13
+ - pt
7
14
 
8
15
  - Incomplete locales:
9
16
  - da
10
17
  - de
11
18
  - ee
12
- - it
13
19
  - lt
14
20
  - lv
15
21
  - sv
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
3
5
 
4
6
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
8
10
  end
9
11
 
10
- task :default => :test
12
+ task default: :test
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "issuer_response_codes"
3
+ require 'bundler/setup'
4
+ require 'issuer_response_codes'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,7 @@ require "issuer_response_codes"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
14
- IRB.start(__FILE__)
13
+ include ::IssuerResponseCodes
14
+
15
+ require 'irb'
16
+ ::IRB.start(__FILE__)
@@ -3,34 +3,28 @@
3
3
  require_relative 'lib/issuer_response_codes/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "issuer_response_codes"
6
+ spec.name = 'issuer_response_codes'
7
7
  spec.version = IssuerResponseCodes::VERSION
8
- spec.authors = ["Espago", "Mateusz Drewniak"]
9
- spec.email = ["m.drewniak@espago.com"]
8
+ spec.authors = ['Espago', 'Mateusz Drewniak']
9
+ spec.email = ['m.drewniak@espago.com']
10
10
 
11
- spec.summary = "Issuer Response Code descriptions for cardholders and merchants"
12
- spec.description = "A simple Ruby gem which provides Issuer Response Code descriptions and suggestions for cardholders and merchants"
13
- spec.homepage = "https://github.com/espago/issuer_response_codes"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5")
11
+ spec.summary = 'Issuer Response Code descriptions for cardholders and merchants'
12
+ spec.description =
13
+ 'A simple Ruby gem which provides Issuer Response Code descriptions and suggestions for cardholders and merchants'
14
+ spec.homepage = 'https://github.com/espago/issuer_response_codes'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.0')
16
17
 
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://github.com/espago/issuer_response_codes"
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/espago/issuer_response_codes'
19
20
 
20
21
  # Specify which files should be added to the gem when it is released.
21
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
23
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
25
  end
25
- spec.bindir = "exe"
26
+ spec.bindir = 'exe'
26
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
28
-
29
- spec.add_development_dependency 'bundler'
30
- spec.add_development_dependency 'bundler-audit'
31
- spec.add_development_dependency 'byebug'
32
- spec.add_development_dependency 'minitest', '~> 5.0'
33
- spec.add_development_dependency 'rake', '~> 12.0'
34
- spec.add_development_dependency 'rubocop'
35
- spec.add_development_dependency 'solargraph'
28
+ spec.require_paths = ['lib']
29
+ spec.metadata['rubygems_mfa_required'] = 'true'
36
30
  end
@@ -1,11 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IssuerResponseCodes
4
+ # ISO-8583 Response code.
4
5
  class Code
5
6
  attr_reader :id, :target, :locale, :fraud_notice
6
7
 
7
8
  NOT_PROVIDED = ::Object.new
8
9
 
10
+ # @param id [String]
11
+ # @param target [Symbol]
12
+ # @param locale [Symbol]
13
+ # @param fraud_notice [Boolean, Object]
9
14
  def initialize(id:, target: :merchant, locale: :en, fraud_notice: NOT_PROVIDED)
10
15
  @id = id
11
16
  @target = target
@@ -22,25 +27,35 @@ module IssuerResponseCodes
22
27
  @fraud_notice = target == :merchant
23
28
  end
24
29
 
30
+ # @return [String]
25
31
  def humanize
26
32
  "#{reason} #{behaviour}"
27
33
  end
28
-
29
34
  alias description humanize
30
35
 
36
+ # @return [String]
31
37
  def reason
32
- LOCALE_LIBRARY.dig(path: id, scope: "issuer_response_codes.targeted.#{target}", locale: locale, default: :unknown)
38
+ LOCALE_LIBRARY[path: id,
39
+ scope: "issuer_response_codes.targeted.#{target}",
40
+ locale: locale,
41
+ default: :unknown]
33
42
  end
34
43
 
44
+ # @return [String]
35
45
  def behaviour
36
- behaviour_str = LOCALE_LIBRARY.dig(path: id, scope: "issuer_response_codes.behaviour", locale: locale, default: :unknown)
46
+ behaviour_str = LOCALE_LIBRARY[path: id,
47
+ scope: 'issuer_response_codes.behaviour',
48
+ locale: locale,
49
+ default: :unknown]
37
50
  return behaviour_str unless fraud_notice && fraudulent_code?
38
51
 
39
- "#{behaviour_str} #{LOCALE_LIBRARY.dig(path: 'issuer_response_codes.fraud_notice')}"
52
+ "#{behaviour_str} #{LOCALE_LIBRARY[path: 'issuer_response_codes.fraud_notice']}"
40
53
  end
41
54
 
55
+ # @return [Boolean]
42
56
  def fraudulent_code?
43
- @fraudulent_code ||= LOCALE_LIBRARY.dig(path: id, scope: "issuer_response_codes.fraudulent_codes", locale: locale)
57
+ @fraudulent_code ||= LOCALE_LIBRARY[path: id, scope: 'issuer_response_codes.fraudulent_codes', locale: locale]
44
58
  end
59
+
45
60
  end
46
61
  end
@@ -1,11 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IssuerResponseCodes
4
+ # Context stores default settings for retrieving codes.
4
5
  class Context
5
6
  attr_reader :default_target, :default_locale, :fraud_notice_by_default
6
7
 
7
8
  NOT_PROVIDED = ::Object.new
8
9
 
10
+ # @param default_target [Symbol]
11
+ # @param default_locale [Symbol]
12
+ # @param fraud_notice_by_default [Boolean, Object]
13
+ # @raise [IllegalLocale]
14
+ # @raise [IllegalTarget]
9
15
  def initialize(default_target: :merchant, default_locale: :en, fraud_notice_by_default: NOT_PROVIDED)
10
16
  @default_target = default_target
11
17
  @default_locale = default_locale
@@ -21,10 +27,20 @@ module IssuerResponseCodes
21
27
  @fraud_notice_by_default = default_target == :merchant
22
28
  end
23
29
 
30
+ # @param id [String, Symbol]
31
+ # @param target [Symbol]
32
+ # @param locale [Symbol]
33
+ # @param fraud_notice [Boolean, Object]
34
+ # @return [Code]
24
35
  def code(id:, target: default_target, locale: default_locale, fraud_notice: fraud_notice_by_default)
25
36
  Code.new(id: id, target: target, locale: locale, fraud_notice: fraud_notice)
26
37
  end
27
38
 
39
+ # @param id [String, Symbol]
40
+ # @param target [Symbol]
41
+ # @param locale [Symbol]
42
+ # @param fraud_notice [Boolean, Object]
43
+ # @return [TdsCode]
28
44
  def tds_code(id:, target: default_target, locale: default_locale, fraud_notice: fraud_notice_by_default)
29
45
  TdsCode.new(id: id, target: target, locale: locale, fraud_notice: fraud_notice)
30
46
  end
@@ -3,6 +3,7 @@
3
3
  require 'yaml'
4
4
 
5
5
  module IssuerResponseCodes
6
+ # Stores the translations of codes.
6
7
  class LocaleLibrary
7
8
  attr_reader :locale_hash
8
9
 
@@ -14,21 +15,25 @@ module IssuerResponseCodes
14
15
  end
15
16
  end
16
17
 
17
- def dig(path:, locale: :en, scope: '', default: nil, substitute: '')
18
- result = __dig__(path: path, locale: locale, scope: scope, default: default)
19
- return result unless result
20
- return result unless result.is_a? ::String
21
-
22
- result.gsub(/%{substitute}/, substitute)
18
+ # @param path [String]
19
+ # @param locale [Symbol]
20
+ # @param scope [String]
21
+ # @param default [Symbol, String, nil]
22
+ # @return [String, Hash, nil]
23
+ def dig(path:, locale: :en, scope: '', default: nil)
24
+ __dig__(path: path, locale: locale, scope: scope, default: default)
23
25
  end
26
+ alias [] dig
24
27
 
28
+ # @param locale [Symbol]
29
+ # @return [Hash{SYmbol => Hash{Symbol => Object}}]
25
30
  def issuer_response_codes(locale: :en)
26
31
  fraudulent_codes = locale_hash.dig(locale, :issuer_response_codes, :fraudulent_codes)
27
32
  behaviours = locale_hash.dig(locale, :issuer_response_codes, :behaviour)
28
33
  cardholder_reasons = locale_hash.dig(locale, :issuer_response_codes, :targeted, :cardholder)
29
34
  merchant_reasons = locale_hash.dig(locale, :issuer_response_codes, :targeted, :merchant)
30
35
 
31
- merchant_reasons.map do |code, merchant_reason|
36
+ merchant_reasons.to_h do |code, merchant_reason|
32
37
  [
33
38
  code,
34
39
  {
@@ -38,16 +43,18 @@ module IssuerResponseCodes
38
43
  fraudulent: fraudulent_codes[code] == true
39
44
  }
40
45
  ]
41
- end.to_h
46
+ end
42
47
  end
43
48
 
49
+ # @param locale [Symbol]
50
+ # @return [Hash{Symbol => Hash{Symbol => Object}}]
44
51
  def tds_codes(locale: :en)
45
52
  fraudulent_codes = locale_hash.dig(locale, :tds_status_codes, :fraudulent_codes)
46
53
  behaviours = locale_hash.dig(locale, :tds_status_codes, :behaviour)
47
54
  cardholder_reasons = locale_hash.dig(locale, :tds_status_codes, :targeted, :cardholder)
48
55
  merchant_reasons = locale_hash.dig(locale, :tds_status_codes, :targeted, :merchant)
49
56
 
50
- merchant_reasons.map do |code, merchant_reason|
57
+ merchant_reasons.to_h do |code, merchant_reason|
51
58
  [
52
59
  code,
53
60
  {
@@ -57,25 +64,16 @@ module IssuerResponseCodes
57
64
  fraudulent: fraudulent_codes[code] == true
58
65
  }
59
66
  ]
60
- end.to_h
61
- end
62
-
63
- def self.symbolize_keys(hash)
64
- h = hash.map do |k, v|
65
- v_sym = if v.instance_of? Hash
66
- symbolize_keys(v)
67
- else
68
- v
69
- end
70
-
71
- [k.to_sym, v_sym]
72
67
  end
73
-
74
- h.to_h
75
68
  end
76
69
 
77
70
  private
78
71
 
72
+ # @param path [String]
73
+ # @param locale [Symbol]
74
+ # @param scope [String]
75
+ # @param default [Symbol, String, nil]
76
+ # @return [String, Hash, nil]
79
77
  def __dig__(path:, locale: :en, scope: '', default: nil)
80
78
  result = dig_provided_path(path, scope, locale)
81
79
  return result if result || !default
@@ -85,6 +83,10 @@ module IssuerResponseCodes
85
83
  dig_provided_path(default.to_s, scope, locale)
86
84
  end
87
85
 
86
+ # @param path [String]
87
+ # @param locale [Symbol]
88
+ # @param scope [String]
89
+ # @return [String, Hash, nil]
88
90
  def dig_provided_path(path, scope, locale)
89
91
  return if path.nil? || path.empty?
90
92
 
@@ -95,12 +97,35 @@ module IssuerResponseCodes
95
97
  locale_hash.dig(*full_path_array)
96
98
  end
97
99
 
100
+ # @param name [Symbol, String]
101
+ # @return [void]
98
102
  def load_locale(name)
99
- name_str = name.to_s
103
+ raw_hash = load_yaml(::File.join(::File.dirname(::File.expand_path(__FILE__)), "../locale/#{name}.yml"))
104
+ name = name.to_sym
100
105
 
101
- raw_hash = ::YAML.load_file(::File.join(::File.dirname(::File.expand_path(__FILE__)), "../locale/#{name_str}.yml"))[name_str]
102
- single_locale_hash = self.class.symbolize_keys(raw_hash)
103
- @locale_hash[name] = single_locale_hash
106
+ @locale_hash[name] = raw_hash[name]
104
107
  end
108
+
109
+ if ::Psych::VERSION > '4'
110
+ # @param file_path [String]
111
+ # @return [Hash{Symbol => Object}]
112
+ def load_yaml(file_path)
113
+ ::YAML.load_file(
114
+ file_path,
115
+ symbolize_names: true,
116
+ aliases: true
117
+ )
118
+ end
119
+ else
120
+ # @param file_path [String]
121
+ # @return [Hash{Symbol => Object}]
122
+ def load_yaml(file_path)
123
+ ::YAML.load_file(
124
+ file_path,
125
+ symbolize_names: true
126
+ )
127
+ end
128
+ end
129
+
105
130
  end
106
131
  end