This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
"files": ["src/index.ts", "src/apidoc.d.ts"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Order { | |
id: number; | |
productId: number; | |
quantity: number; | |
shipDate: string; | |
status: "placed" | "approved" | "delivered"; | |
complete: boolean; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeService | |
def call | |
call_service_a | |
end | |
private | |
def service_a | |
# ... uses status objects | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case result | |
when Success then | |
# success handler | |
when SpecificError then | |
# specific error handler | |
when Error then | |
# error handler | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Success = Struct.new(:data) do | |
def success? | |
true | |
end | |
end | |
Error = Struct.new(:error, :code, :details) do | |
def error_message | |
error.to_s | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ServiceObject | |
attr_reader :input | |
# ... | |
private | |
def private_method_with_input | |
input.field # access input as method | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class APIResponder < ActionController::Responder | |
private | |
def display(resource, options = {}) | |
super(resource.data, options) | |
end | |
def has_errors? | |
!resource.success? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe CreateInvoice do | |
subject { CreateInvoice.new(user, notification_center, form) } | |
let(:user) { instance_double("User", subscriber?: true) } | |
let(:notification_center) { instance_double("NotificationCenter", invoice_created: nil) | |
let(:form) { instance_double("InvoiceForm", company_name: "ACME Corp.", billing_date: Time.now) | |
describe "passing valid parameters" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InvoicesController < ApplicationController | |
# ... | |
def create | |
form = InvoiceForm.new(params) | |
result = CreateInvoice.new(current_user, form).call | |
@invoice = result.invoice | |
if result.success? | |
redirect_to @invoice | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InvoiceForm | |
attr_reader :params | |
def initialize(params) | |
@params = params | |
end | |
def billing_date | |
Time.new(params[:year], params[:month], params[:day]) if time_data_present? | |
rescue ArgumentError | |
end |
NewerOlder