Skip to content

Commit

Permalink
chore: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ksol committed Dec 26, 2023
1 parent 7edb64a commit edd5a06
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 60 deletions.
30 changes: 9 additions & 21 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
inherit_from: []

inherit_gem:
standard: config/base.yml

require:
- standard
- standard-custom
- standard-performance
- rubocop-performance

inherit_gem:
standard: config/base.yml
standard-custom: config/base.yml
standard-performance: config/base.yml

AllCops:
TargetRubyVersion: 3.0
NewCops: enable
SuggestExtensions: false
Exclude:
- 'node_modules/**/*'
- 'tmp/**/*'
- 'vendor/**/*'
- '.git/**/*'

Style/TrailingCommaInArguments:
Enabled: true
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInArrayLiteral:
Enabled: true
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInHashLiteral:
Enabled: true
EnforcedStyleForMultiline: consistent_comma

Style/Alias:
Enabled: true
EnforcedStyle: prefer_alias_method
8 changes: 4 additions & 4 deletions lib/scalingo/api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def self.register_handlers!(handlers)

def self.register_handler!(method_name, klass)
define_method(method_name) do
value = instance_variable_get("@#{method_name}")
value = instance_variable_get(:"@#{method_name}")

if value.nil?
value = klass.new(self)
instance_variable_set("@#{method_name}", value)
instance_variable_set(:"@#{method_name}", value)
end

value
Expand All @@ -54,7 +54,7 @@ def inspect
def headers
hash = {
"User-Agent" => config.user_agent,
"Accept" => "application/json",
"Accept" => "application/json"
}

if (extra = config.additional_headers).present?
Expand All @@ -67,7 +67,7 @@ def headers
def connection_options
{
url: url,
headers: headers,
headers: headers
}
end

Expand Down
6 changes: 3 additions & 3 deletions lib/scalingo/api/response.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Scalingo
module API
class Response
def self.unpack(client, key: nil, keys: nil, &block)
response = block.call
def self.unpack(client, key: nil, keys: nil)
response = yield

body = response.body
has_hash_body = body.present? && body.respond_to?(:key)
Expand All @@ -24,7 +24,7 @@ def self.unpack(client, key: nil, keys: nil, &block)
headers: response.headers,
data: data,
meta: meta,
full_body: body,
full_body: body
)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/scalingo/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Auth < API::Client
scm_integrations: ScmIntegrations,
tokens: Tokens,
two_factor_auth: TwoFactorAuth,
user: User,
user: User
)

alias_method :tfa, :two_factor_auth
Expand Down
2 changes: 1 addition & 1 deletion lib/scalingo/auth/tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def exchange(token, headers = nil, &block)
authorization = Faraday::Request::BasicAuthentication.header("", token)

request_headers = {
Faraday::Request::Authorization::KEY => authorization,
Faraday::Request::Authorization::KEY => authorization
}

request_headers.update(headers) if headers
Expand Down
2 changes: 1 addition & 1 deletion lib/scalingo/billing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Billing < API::Client
require "scalingo/billing/profile"

register_handlers!(
profile: Profile,
profile: Profile
)
end
end
12 changes: 6 additions & 6 deletions lib/scalingo/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@ class Client < CoreClient
def auth
@auth ||= Auth.new(
"https://auth.scalingo.com/v1",
scalingo: self,
scalingo: self
)
end

def billing
@billing ||= Billing.new(
"https://cashmachine.scalingo.com",
scalingo: self,
scalingo: self
)
end

def osc_fr1
@osc_fr1 ||= Regional.new(
"https://api.osc-fr1.scalingo.com/v1",
scalingo: self,
scalingo: self
)
end
alias_method :apps_api_osc_fr1, :osc_fr1

def osc_secnum_fr1
@osc_secnum_fr1 ||= Regional.new(
"https://api.osc-secnum-fr1.scalingo.com/v1",
scalingo: self,
scalingo: self
)
end
alias_method :apps_api_osc_secnum_fr1, :osc_secnum_fr1

def db_api_osc_fr1
@db_api_osc_fr1 ||= RegionalDatabase.new(
"https://db-api.osc-fr1.scalingo.com/api",
scalingo: self,
scalingo: self
)
end

def db_api_osc_secnum_fr1
@db_api_osc_secnum_fr1 ||= RegionalDatabase.new(
"https://db-api.osc-secnum-fr1.scalingo.com/api",
scalingo: self,
scalingo: self
)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/scalingo/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Configuration
:additional_headers,

# Specify an adapter for faraday. Leave nil for the default one (Net::HTTP)
:faraday_adapter,
:faraday_adapter
]

ATTRIBUTES.each { |attr| attr_accessor(attr) }
Expand All @@ -49,13 +49,13 @@ def self.default
exchanged_token_validity: 1.hour,
raise_on_missing_authentication: true,
raise_on_expired_token: false,
additional_headers: {},
additional_headers: {}
)
end

def initialize(attributes = {}, parent = nil)
ATTRIBUTES.each do |name|
public_send("#{name}=", attributes.fetch(name, parent&.public_send(name)))
public_send(:"#{name}=", attributes.fetch(name, parent&.public_send(name)))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/scalingo/core_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def authenticate_with(access_token: nil, bearer_token: nil, expires_at: nil)
self.token = BearerToken.new(
response.data[:token],
expires_at: expiration,
raise_on_expired: config.raise_on_expired_token,
raise_on_expired: config.raise_on_expired_token
)
end

Expand All @@ -78,7 +78,7 @@ def authenticate_with(access_token: nil, bearer_token: nil, expires_at: nil)
authenticate_with_bearer_token(
bearer_token,
expires_at: expires_at,
raise_on_expired_token: config.raise_on_expired_token,
raise_on_expired_token: config.raise_on_expired_token
)

true
Expand Down
2 changes: 1 addition & 1 deletion lib/scalingo/regional.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Regional < API::Client
metrics: Metrics,
notifiers: Notifiers,
operations: Operations,
scm_repo_links: ScmRepoLinks,
scm_repo_links: ScmRepoLinks
)
end
end
2 changes: 1 addition & 1 deletion lib/scalingo/regional/addons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def authenticate!(app_id, addon_id, headers = nil, &block)
addon_id,
token,
expires_at: Time.now + 1.hour,
raise_on_expired_token: client.config.raise_on_expired_token,
raise_on_expired_token: client.config.raise_on_expired_token
)

response
Expand Down
2 changes: 1 addition & 1 deletion lib/scalingo/regional_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RegionalDatabase < API::Client

register_handlers!(
databases: Databases,
backups: Backups,
backups: Backups
)
end
end
2 changes: 1 addition & 1 deletion lib/scalingo/token_holder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def build_bearer_token(bearer_token, expires_at:, raise_on_expired_token:)
BearerToken.new(
token,
expires_at: expires_at,
raise_on_expired: raise_on_expired_token,
raise_on_expired: raise_on_expired_token
)
end
end
Expand Down
6 changes: 2 additions & 4 deletions scalingo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |s|
"changelog_uri" => "https://github.com/Scalingo/scalingo-ruby-api/blob/master/CHANGELOG.md",
"documentation_uri" => "https://developers.scalingo.com/",
"homepage_uri" => "https://www.scalingo.com/",
"source_code_uri" => "https://github.com/Scalingo/scalingo-ruby-api",
"source_code_uri" => "https://github.com/Scalingo/scalingo-ruby-api"
}

# Specify which files should be added to the gem when it is released.
Expand All @@ -32,8 +32,6 @@ Gem::Specification.new do |s|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
s.require_paths = ["lib"]

s.test_files = Dir["spec/**/*_spec.rb"]

s.add_dependency "activesupport", [">= 5", "< 8"]
s.add_dependency "faraday", "~> 1.0"
s.add_dependency "faraday_middleware", "~> 1.0"
Expand All @@ -42,7 +40,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "bundler", "~> 2.0"
s.add_development_dependency "rake", "~> 13.0"
s.add_development_dependency "rspec", "~> 3.0"
s.add_development_dependency "standard", "~> 1.1.0"
s.add_development_dependency "standard", "~> 1.32"
s.add_development_dependency "rubocop-rspec"
s.add_development_dependency "pry", "~> 0.14.1"
s.add_development_dependency "webmock", "~> 3.12.2"
Expand Down
2 changes: 1 addition & 1 deletion spec/scalingo/api/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
database_id_2,
"1234",
expires_at: Time.now + 1.hour,
raise_on_expired_token: false,
raise_on_expired_token: false
)
expect {
subject.database_connection(database_id)
Expand Down
4 changes: 2 additions & 2 deletions spec/scalingo/api/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
headers: headers,
data: data,
full_body: full_body,
meta: meta_object,
meta: meta_object
)
}

Expand All @@ -28,7 +28,7 @@
body: body,
status: status,
headers: headers,
success?: success,
success?: success
)
}

Expand Down
4 changes: 2 additions & 2 deletions spec/scalingo/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
it "is successful with valid token" do
fake_response = OpenStruct.new(
successful?: true,
data: {token: "response token"},
data: {token: "response token"}
)

expect(subject.auth.tokens).to receive(:exchange).and_return(fake_response)
Expand All @@ -64,7 +64,7 @@

it "fails with invalid token" do
fake_response = OpenStruct.new(
successful?: false,
successful?: false
)

expect(subject.auth.tokens).to receive(:exchange).and_return(fake_response)
Expand Down
9 changes: 4 additions & 5 deletions spec/support/scalingo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Scalingo
auth: "https://auth.scalingo.test",
billing: "https://billing.scalingo.test",
regional: "https://regional.scalingo.test",
regional_database: "https://regional-database.scalingo.test",
regional_database: "https://regional-database.scalingo.test"
}

class SpecClient < CoreClient
Expand Down Expand Up @@ -59,8 +59,7 @@ def register_stubs!(pattern = "**/*", api: nil, folder: nil)
url = stub_data[:url] || File.join(endpoint, stub_data[:path])
method = (stub_data[:method] || :get).to_sym

request_options = {
}
request_options = {}

if stub_data[:request].present?
req = stub_data[:request]
Expand All @@ -79,7 +78,7 @@ def register_stubs!(pattern = "**/*", api: nil, folder: nil)

response_options = {
status: stub_data.dig(:response, :status) || 200,
headers: {},
headers: {}
}

if stub_data.dig(:response, :json_body).present?
Expand Down Expand Up @@ -142,7 +141,7 @@ module Common
if described_class < Scalingo::API::Endpoint
api = described_class.to_s.split("::")[-2].downcase

described_class.new(send("#{api}_guest"))
described_class.new(send(:"#{api}_guest"))
end
end

Expand Down

0 comments on commit edd5a06

Please sign in to comment.