Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit 883d616

Browse files
authored
Updates ruby and rubocop setup (#40)
* Adds rubocop and rubocop-performance to the development dependencies * Adds binstub for rubocop * Updates .rubocop.yml * Remove ruby versions < 2.3 from supported ruby versions * Sets Target ruby version to 2.6.3
1 parent 1e83efd commit 883d616

File tree

10 files changed

+69
-20
lines changed

10 files changed

+69
-20
lines changed

.codeclimate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ engines:
1212
enabled: true
1313
rubocop:
1414
enabled: true
15+
channel: rubocop-0-71
1516
ratings:
1617
paths:
1718
- "**.inc"

.rubocop.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
require: rubocop-performance
2+
13
AllCops:
2-
TargetRubyVersion: 2.5
4+
TargetRubyVersion: 2.6
35
Exclude:
46
- vendor/**/*
7+
- bin/*
58

69
Naming/AccessorMethodName:
710
Description: Check the naming of accessor methods for get_/set_.
@@ -39,6 +42,11 @@ Naming/PredicateName:
3942
Exclude:
4043
- spec/**/*
4144

45+
Naming/RescuedExceptionsVariableName:
46+
Description: 'Use consistent rescued exceptions variables naming.'
47+
Enabled: true
48+
PreferredName: error
49+
4250
Style/Alias:
4351
Description: 'Use alias_method instead of alias.'
4452
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#alias-method'
@@ -133,7 +141,7 @@ Style/EvenOdd:
133141
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods'
134142
Enabled: false
135143

136-
Style/FlipFlop:
144+
Lint/FlipFlop:
137145
Description: 'Checks for flip flops'
138146
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-flip-flops'
139147
Enabled: false
@@ -266,6 +274,13 @@ Style/RegexpLiteral:
266274
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-r'
267275
Enabled: false
268276

277+
Style/Sample:
278+
Description: >-
279+
Use `sample` instead of `shuffle.first`,
280+
`shuffle.last`, and `shuffle[Fixnum]`.
281+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code'
282+
Enabled: false
283+
269284
Style/SelfAssignment:
270285
Description: >-
271286
Checks for places where self-assignment shorthand should have
@@ -626,13 +641,6 @@ Performance/ReverseEach:
626641
Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code'
627642
Enabled: false
628643

629-
Performance/Sample:
630-
Description: >-
631-
Use `sample` instead of `shuffle.first`,
632-
`shuffle.last`, and `shuffle[Fixnum]`.
633-
Reference: 'https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code'
634-
Enabled: false
635-
636644
Performance/Size:
637645
Description: >-
638646
Use `size` instead of `count` for counting

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.5.3
1+
2.6.3

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ sudo: false
22
language: ruby
33
cache: bundler
44
rvm:
5-
- 2.2
65
- 2.3
76
- 2.4
87
- 2.5

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Deprecated
88

99
### Removed
10+
- Removed support for ruby < 2.3. Target ruby version is 2.6
1011

1112
### Fixed
1213

bin/rubocop

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rubocop' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("rubocop", "rubocop")

lib/shipcloud.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
require "net/http"
23
require "net/https"
34
require "json"
@@ -10,10 +11,11 @@ module Shipcloud
1011

1112
API_HEADERS = {
1213
"Content-Type" => "application/json",
13-
"User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API #{Shipcloud::API_VERSION}, #{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}"
14-
}
14+
"User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API #{Shipcloud::API_VERSION}, " \
15+
"#{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}",
16+
}.freeze
1517

16-
DEFAULT_AFFILIATE_ID = "integration.shipcloud-ruby-gem.v#{Shipcloud::VERSION}".freeze
18+
DEFAULT_AFFILIATE_ID = "integration.shipcloud-ruby-gem.v#{Shipcloud::VERSION}"
1719

1820
autoload :Base, "shipcloud/base"
1921
autoload :Shipment, "shipcloud/shipment"
@@ -39,12 +41,14 @@ module Request
3941
end
4042

4143
class << self
42-
attr_accessor :configuration
44+
attr_writer :configuration
4345
end
4446

47+
# rubocop:disable Naming/MemoizedInstanceVariableName
4548
def self.configuration
4649
@configuration ||= Configuration.new
4750
end
51+
# rubocop:enable Naming/MemoizedInstanceVariableName
4852

4953
def self.configure
5054
yield(configuration)
@@ -61,7 +65,7 @@ class Configuration
6165

6266
def initialize
6367
@api_key = nil
64-
@api_base = 'api.shipcloud.io'
68+
@api_base = "api.shipcloud.io"
6569
@use_ssl = true
6670
@debug = false
6771
end

lib/shipcloud/request/base.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def initialize(info)
99

1010
def perform
1111
raise AuthenticationError unless @info.api_key
12+
1213
connection.setup_https
1314
response = connection.request
1415
validate_response(response)
@@ -26,9 +27,11 @@ def validate_response(response)
2627
end
2728
end
2829

30+
# rubocop:disable Naming/MemoizedInstanceVariableName
2931
def connection
3032
@connection ||= Connection.new(info)
3133
end
34+
# rubocop:enable Naming/MemoizedInstanceVariableName
3235
end
3336
end
3437
end

lib/shipcloud/shipcloud_error.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def self.error_class_for(response_code)
3939

4040
def parse_errors
4141
return [] unless response_body
42+
4243
data = JSON.parse(response_body)
4344
if data.is_a?(Hash) && data["errors"]
4445
data["errors"]
@@ -51,6 +52,7 @@ def parse_errors
5152

5253
def response_body
5354
return unless @response
55+
5456
@response.body
5557
end
5658
end

shipcloud.gemspec

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding: utf-8
2-
lib = File.expand_path("../lib", __FILE__)
2+
lib = File.expand_path("lib", __dir__)
33
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
44
require "shipcloud/version"
55

@@ -19,12 +19,14 @@ Gem::Specification.new do |spec|
1919
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
2020
spec.require_paths = ["lib"]
2121

22-
spec.required_ruby_version = ">= 2.0"
22+
spec.required_ruby_version = ">= 2.3"
2323

2424
spec.add_runtime_dependency "json", ">= 1.8.0"
25+
spec.add_development_dependency "pry", "~> 0.10"
2526
spec.add_development_dependency "rake", "~> 12.0"
2627
spec.add_development_dependency "rspec", "~> 3.6"
27-
spec.add_development_dependency "webmock", "~> 3.0"
28-
spec.add_development_dependency "pry", "~> 0.10"
28+
spec.add_development_dependency "rubocop", "~> 0.71.0"
29+
spec.add_development_dependency "rubocop-performance"
2930
spec.add_development_dependency "simplecov"
31+
spec.add_development_dependency "webmock", "~> 3.0"
3032
end

0 commit comments

Comments
 (0)