Skip to content

Commit

Permalink
Add Rubocop and and fix compliance (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields authored Apr 26, 2023
1 parent 3804065 commit e4eb445
Show file tree
Hide file tree
Showing 22 changed files with 466 additions and 348 deletions.
21 changes: 17 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@ name: Test
on: [push, pull_request]

jobs:
rubocop:
runs-on: ubuntu-latest
env:
CI: true
steps:
- uses: actions/checkout@v3
- name: Set up Ruby 3.2
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true
- name: Run RuboCop
run: bundle exec rubocop --parallel

test:
name: Unit test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
ruby-version: [2.6, 2.7, 3.0, 3.1, 3.2, jruby-9.4, truffleruby]
runs-on: ${{ matrix.os }}
env:
CI: true
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}

- name: Install dependencies
run: bundle install

- name: Run tests
run: bundle exec rspec
37 changes: 37 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
inherit_from: .rubocop_todo.yml

# inherit_from: .rubocop_todo.yml

require:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.6
NewCops: enable
Exclude:
- 'data/**/*'
- 'vendor/**/*'

Metrics/CollectionLiteralLength:
Exclude:
- 'lib/paygate/aes.rb'

Naming/FileName:
Exclude:
- 'lib/paygate-ruby.rb'

Naming/MethodParameterName:
Exclude:
- 'lib/paygate/aes.rb'
- 'lib/paygate/aes_ctr.rb'

RSpec/NotToNot:
EnforcedStyle: to_not

Style/Documentation:
Enabled: false

Style/ModuleFunction:
EnforcedStyle: extend_self
27 changes: 27 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-04-26 08:36:11 UTC using RuboCop version 1.50.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 7
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 93

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 113

# Offense count: 8
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 35

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 123
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [PR#9](https://github.com/tablecheck/paygate-ruby/pull/9) Do not include Paygate::FormHelper in ActionView::Base. ([johnnyshields](https://github.com/johnnyshields))
- [PR#9](https://github.com/tablecheck/paygate-ruby/pull/9) Update BIN list. Note BINs can now be a flexible number of digits. ([johnnyshields](https://github.com/johnnyshields))
- [PR#9](https://github.com/tablecheck/paygate-ruby/pull/9) Rename data config YAML keys. ([johnnyshields](https://github.com/johnnyshields))
- [PR#10](https://github.com/tablecheck/paygate-ruby/pull/10) Add Rubocop and fix compliance issues. ([johnnyshields](https://github.com/johnnyshields))

## 0.1.11 - 2022-05-13

Expand Down
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

group :development, :test do
Expand All @@ -6,6 +8,10 @@ end

group :test do
gem 'rspec'
gem 'rubocop', '~> 1.49.0'
gem 'rubocop-performance', '~> 1.16.0'
gem 'rubocop-rake', '~> 0.6.0'
gem 'rubocop-rspec', '~> 2.19.0'
gem 'timecop'
end

Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
44 changes: 2 additions & 42 deletions lib/paygate-ruby.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
require 'yaml'
require 'paygate/version'
require 'paygate/configuration'
require 'paygate/aes'
require 'paygate/aes_ctr'
require 'paygate/member'
require 'paygate/response'
require 'paygate/transaction'
require 'paygate/profile'
require 'paygate/action_view/form_helper' if defined?(ActionView)
# frozen_string_literal: true

module Paygate
CONFIG = YAML.load(File.read(File.expand_path('../data/config.yml', File.dirname(__FILE__)))).freeze
LOCALES_MAP = CONFIG[:locales].freeze
INTL_BRANDS_MAP = CONFIG[:intl_brands].freeze
KOREA_BIN_NUMBERS = CONFIG[:korea_bin_numbers].freeze
DEFAULT_CURRENCY = 'WON'.freeze
DEFAULT_LOCALE = 'US'.freeze

def mapped_currency(currency)
return DEFAULT_CURRENCY unless currency.present?

currency.to_s == 'KRW' ? 'WON' : currency.to_s
end
module_function :mapped_currency

def mapped_locale(locale)
locale.present? ? LOCALES_MAP[locale.to_s] : DEFAULT_LOCALE
end
module_function :mapped_locale

class << self
attr_writer :configuration
end

def self.configuration
@configuration ||= Configuration.new
end

def self.configure
yield configuration
end
end
require 'paygate'
43 changes: 43 additions & 0 deletions lib/paygate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'yaml'
require 'paygate/version'
require 'paygate/configuration'
require 'paygate/aes'
require 'paygate/aes_ctr'
require 'paygate/member'
require 'paygate/response'
require 'paygate/transaction'
require 'paygate/profile'
require 'paygate/action_view/form_helper' if defined?(ActionView)

module Paygate
extend self

CONFIG = YAML.safe_load(File.read(File.expand_path('../data/config.yml', __dir__)),
permitted_classes: [Symbol]).freeze
LOCALES_MAP = CONFIG[:locales].freeze
INTL_BRANDS_MAP = CONFIG[:intl_brands].freeze
KOREA_BIN_NUMBERS = CONFIG[:korea_bin_numbers].freeze
DEFAULT_CURRENCY = 'WON'
DEFAULT_LOCALE = 'US'

def mapped_currency(currency)
currency = currency&.to_s
return DEFAULT_CURRENCY if currency.nil?

currency.to_s == 'KRW' ? 'WON' : currency.to_s
end

def mapped_locale(locale)
LOCALES_MAP[locale&.to_s] || DEFAULT_LOCALE
end

def configuration
@configuration ||= Configuration.new
end

def configure
yield(configuration)
end
end
Loading

0 comments on commit e4eb445

Please sign in to comment.