Skip to content

Commit

Permalink
misc: Fix rubocop warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Apr 24, 2023
1 parent a08a35a commit 18528ec
Show file tree
Hide file tree
Showing 328 changed files with 1,846 additions and 1,745 deletions.
2 changes: 2 additions & 0 deletions .irbrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

IRB.conf[:USE_AUTOCOMPLETE] = false
6 changes: 4 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative "config/application"
require "graphql/rake_task"
require_relative 'config/application'
require 'graphql/rake_task'

Rails.application.load_tasks

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def forbidden_error(code:)
json: {
status: 403,
error: 'Forbidden',
code: code,
code:,
},
status: :forbidden,
)
Expand All @@ -62,7 +62,7 @@ def method_not_allowed_error(code:)
json: {
status: 405,
error: 'Method Not Allowed',
code: code,
code:,
},
status: :method_not_allowed,
)
Expand All @@ -84,7 +84,7 @@ def render_error_response(error_result)
end

def current_organization(api_key = nil)
@current_organization ||= Organization.find_by(api_key: api_key)
@current_organization ||= Organization.find_by(api_key:)
end

def set_context_source
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def update
invoice = current_organization.invoices.find_by(id: params[:id])

result = Invoices::UpdateService.new(
invoice: invoice,
invoice:,
params: update_params.to_h.deep_symbolize_keys,
).call

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/wallet_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def input_params
@input_params ||= params.require(:wallet_transaction).permit(
:wallet_id,
:paid_credits,
:granted_credits
:granted_credits,
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/wallets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def create
current_organization,
input_params
.merge(organization_id: current_organization.id)
.merge(customer: customer),
.merge(customer:),
).create_input,
)

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/authenticable_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def payload_data

def decode_options
{
algorithm: 'HS256'
algorithm: 'HS256',
}
end

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/concerns/common.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Common
extend ActiveSupport::Concern

Expand All @@ -12,4 +14,4 @@ def valid_date?(date)

true
end
end
end
8 changes: 5 additions & 3 deletions app/controllers/concerns/pagination.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Pagination
extend ActiveSupport::Concern

Expand All @@ -12,16 +14,16 @@ def pagination_metadata(records)
'next_page' => records.next_page,
'prev_page' => records.prev_page,
'total_pages' => records.total_pages,
'total_count' => records.total_count
'total_count' => records.total_count,
}
else
{
'current_page' => 0,
'next_page' => nil,
'prev_page' => nil,
'total_pages' => 0,
'total_count' => 0
'total_count' => 0,
}
end
end
end
end
4 changes: 3 additions & 1 deletion app/controllers/concerns/trackable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Trackable
extend ActiveSupport::Concern

Expand All @@ -14,7 +16,7 @@ def membership_id

# NOTE: When doing requests from the API, we haven't the current user information.
# In that case, we add tracing information on the first created membership of the organization.
return first_membership_id unless (defined?(current_user) && current_user)
return first_membership_id unless defined?(current_user) && current_user

current_organization.memberships.find_by(user_id: current_user.id).id
end
Expand Down
30 changes: 16 additions & 14 deletions app/controllers/graphql_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def execute
current_organization:,
customer_portal_user:,
}
result = LagoApiSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
render json: result
result = LagoApiSchema.execute(query, variables:, context:, operation_name:)
render(json: result)
rescue JWT::ExpiredSignature
render_graphql_error(code: 'expired_jwt_token', status: 401)
rescue StandardError => e
Expand Down Expand Up @@ -59,22 +59,24 @@ def prepare_variables(variables_param)
end

def handle_error_in_development(e)
logger.error e.message
logger.error e.backtrace.join("\n")
logger.error(e.message)
logger.error(e.backtrace.join("\n"))

render json: { errors: [{ message: e.message, backtrace: e.backtrace }], data: {} }, status: 500
render(json: { errors: [{ message: e.message, backtrace: e.backtrace }], data: {} }, status: 500)
end

def render_graphql_error(code:, status:, message: nil)
render json: {
data: {},
errors: [
{
message: message || code,
extensions: { status: status, code: code }
}
]
}
render(
json: {
data: {},
errors: [
{
message: message || code,
extensions: { status:, code: },
},
],
},
)
end

def set_context_source
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/concerns/execution_error_responder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module ExecutionErrorResponder

def execution_error(error: 'Internal Error', status: 422, code: 'internal_error', details: nil)
payload = {
status: status,
code: code,
status:,
code:,
}

if details.is_a?(Hash)
Expand All @@ -36,7 +36,7 @@ def not_allowed_error(code:)
execution_error(
error: 'Method Not Allowed',
status: 405,
code: code,
code:,
)
end

Expand Down
21 changes: 8 additions & 13 deletions app/graphql/lago_api_schema.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class LagoApiSchema < GraphQL::Schema
mutation(Types::MutationType)
query(Types::QueryType)
Expand All @@ -6,16 +8,9 @@ class LagoApiSchema < GraphQL::Schema
use GraphQL::Dataloader

# GraphQL-Ruby calls this when something goes wrong while running a query:
def self.type_error(err, context)
# if err.is_a?(GraphQL::InvalidNullError)
# # report to your bug tracker here
# return nil
# end
super
end

# Union and Interface Resolution
def self.resolve_type(abstract_type, obj, ctx)
def self.resolve_type(_abstract_type, _obj, _ctx)
# TODO: Implement this method
# to return the correct GraphQL object type for `obj`
raise(GraphQL::RequiredImplementationMissingError)
Expand All @@ -24,24 +19,24 @@ def self.resolve_type(abstract_type, obj, ctx)
# Relay-style Object Identification:

# Return a string UUID for `object`
def self.id_from_object(object, type_definition, query_ctx)
def self.id_from_object(object, type_definition, _query_ctx)
# For example, use Rails' GlobalID library (https://github.com/rails/globalid):
object_id = object.to_global_id.to_s
# Remove this redundant prefix to make IDs shorter:
object_id = object_id.sub("gid://#{GlobalID.app}/", "")
object_id = object_id.sub("gid://#{GlobalID.app}/", '')
encoded_id = Base64.urlsafe_encode64(object_id)
# Remove the "=" padding
encoded_id = encoded_id.sub(/=+/, "")
encoded_id = encoded_id.sub(/=+/, '')
# Add a type hint
type_hint = type_definition.graphql_name.first
"#{type_hint}_#{encoded_id}"
end

# Given a string UUID, find the object
def self.object_from_id(encoded_id_with_hint, query_ctx)
def self.object_from_id(encoded_id_with_hint, _query_ctx)
# For example, use Rails' GlobalID library (https://github.com/rails/globalid):
# Split off the type hint
_type_hint, encoded_id = encoded_id_with_hint.split("_", 2)
_type_hint, encoded_id = encoded_id_with_hint.split('_', 2)
# Decode the ID
id = Base64.urlsafe_decode64(encoded_id)
# Rebuild it for Rails then find the object:
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/mutations/add_ons/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class Create < BaseMutation
graphql_name 'CreateAddOn'
description 'Creates a new add-on'

argument :name, String, required: true
argument :code, String, required: true
argument :description, String, required: false
argument :amount_cents, GraphQL::Types::BigInt, required: true
argument :amount_currency, Types::CurrencyEnum, required: true
argument :code, String, required: true
argument :description, String, required: false
argument :name, String, required: true

type Types::AddOns::Object

Expand Down
8 changes: 4 additions & 4 deletions app/graphql/mutations/add_ons/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class Update < BaseMutation
graphql_name 'UpdateAddOn'
description 'Update an existing add-on'

argument :id, ID, required: true
argument :name, String, required: true
argument :code, String, required: true
argument :description, String, required: false
argument :amount_cents, GraphQL::Types::BigInt, required: true
argument :amount_currency, Types::CurrencyEnum, required: true
argument :code, String, required: true
argument :description, String, required: false
argument :id, ID, required: true
argument :name, String, required: true

type Types::AddOns::Object

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/mutations/applied_coupons/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class Create < BaseMutation

argument :amount_cents, GraphQL::Types::BigInt, required: false
argument :amount_currency, Types::CurrencyEnum, required: false
argument :percentage_rate, Float, required: false
argument :frequency, Types::Coupons::FrequencyEnum, required: false
argument :frequency_duration, Integer, required: false
argument :percentage_rate, Float, required: false

type Types::AppliedCoupons::Object

Expand Down
4 changes: 2 additions & 2 deletions app/graphql/mutations/billable_metrics/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class Create < BaseMutation
graphql_name 'CreateBillableMetric'
description 'Creates a new Billable metric'

argument :name, String, required: true
argument :aggregation_type, Types::BillableMetrics::AggregationTypeEnum, required: true
argument :code, String, required: true
argument :description, String
argument :aggregation_type, Types::BillableMetrics::AggregationTypeEnum, required: true
argument :field_name, String, required: false
argument :group, GraphQL::Types::JSON, required: false
argument :name, String, required: true

type Types::BillableMetrics::Object

Expand Down
6 changes: 3 additions & 3 deletions app/graphql/mutations/billable_metrics/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class Update < BaseMutation
graphql_name 'UpdateBillableMetric'
description 'Updates an existing Billable metric'

argument :id, String, required: true
argument :name, String, required: true
argument :aggregation_type, Types::BillableMetrics::AggregationTypeEnum, required: true
argument :code, String, required: true
argument :description, String
argument :aggregation_type, Types::BillableMetrics::AggregationTypeEnum, required: true
argument :field_name, String, required: false
argument :group, GraphQL::Types::JSON, required: false
argument :id, String, required: true
argument :name, String, required: true

type Types::BillableMetrics::Object

Expand Down
8 changes: 4 additions & 4 deletions app/graphql/mutations/coupons/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class Create < BaseMutation
graphql_name 'CreateCoupon'
description 'Creates a new Coupon'

argument :name, String, required: true
argument :code, String, required: false
argument :coupon_type, Types::Coupons::CouponTypeEnum, required: true
argument :amount_cents, GraphQL::Types::BigInt, required: false
argument :amount_currency, Types::CurrencyEnum, required: false
argument :percentage_rate, Float, required: false
argument :code, String, required: false
argument :coupon_type, Types::Coupons::CouponTypeEnum, required: true
argument :frequency, Types::Coupons::FrequencyEnum, required: true
argument :frequency_duration, Integer, required: false
argument :name, String, required: true
argument :percentage_rate, Float, required: false
argument :reusable, Boolean, required: false

argument :applies_to, Types::Coupons::LimitationInput, required: false
Expand Down
10 changes: 5 additions & 5 deletions app/graphql/mutations/coupons/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class Update < BaseMutation
graphql_name 'UpdateCoupon'
description 'Update an existing coupon'

argument :id, String, required: true
argument :name, String, required: true
argument :code, String, required: false
argument :coupon_type, Types::Coupons::CouponTypeEnum, required: true
argument :amount_cents, GraphQL::Types::BigInt, required: false
argument :amount_currency, Types::CurrencyEnum, required: false
argument :percentage_rate, Float, required: false
argument :code, String, required: false
argument :coupon_type, Types::Coupons::CouponTypeEnum, required: true
argument :frequency, Types::Coupons::FrequencyEnum, required: true
argument :frequency_duration, Integer, required: false
argument :id, String, required: true
argument :name, String, required: true
argument :percentage_rate, Float, required: false
argument :reusable, Boolean, required: false

argument :applies_to, Types::Coupons::LimitationInput, required: false
Expand Down
4 changes: 2 additions & 2 deletions app/graphql/mutations/credit_notes/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Create < BaseMutation
graphql_name 'CreateCreditNote'
description 'Creates a new Credit Note'

argument :reason, Types::CreditNotes::ReasonTypeEnum, required: true
argument :invoice_id, ID, required: true
argument :description, String, required: false
argument :invoice_id, ID, required: true
argument :reason, Types::CreditNotes::ReasonTypeEnum, required: true

argument :credit_amount_cents, GraphQL::Types::BigInt, required: false
argument :refund_amount_cents, GraphQL::Types::BigInt, required: false
Expand Down
Loading

0 comments on commit 18528ec

Please sign in to comment.