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
require 'timeout' | |
begin | |
status = Timeout::timeout(5) { | |
# Something that should be interrupted if it takes too much time... | |
} | |
rescue Timeout::Error | |
puts 'That took too long, exiting...' | |
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
## Inquiry | |
"production".inquiry.production? # True | |
"active".inquiry.inactive? # False | |
## Normalizes | |
class User < ApplicationRecord | |
normalizes :email, with: ->(email) { email.strip.downcase } | |
end | |
## Generate Token For |
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 OrdersService | |
def call(command) | |
case command | |
when BatchOfCommands | |
batch(command.commands) | |
when ConfirmCommand | |
confirm(command) | |
when SetDeliveryMethodCommand | |
set_delivery(command) | |
# ... |
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 Terms < Struct.new( | |
:invoice_due_at, | |
:credit_note, | |
:release, | |
:optional_reminder1, | |
:optional_reminder2 | |
) | |
end | |
Terms.new( |
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 CapturingProcess < ApplicationJob | |
prepend RailsEventStore::AsyncHandler | |
class State < ActiveRecord::Base | |
self.table_name = "capturing_process_state" | |
serialize :data | |
def self.get_by_order_number(order_number) | |
transaction do | |
lock.find_or_create_by(order_number: order_number).tap do |s| |
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 Product | |
include AggregateRoot | |
def register(store_id:, sku:) | |
apply(ProductRegistered.new(data: { | |
store_id: store_id, | |
sku: sku, | |
})) | |
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
module M | |
def test_method_with_module | |
"Test from M" | |
end | |
end | |
class C | |
def test_method | |
"Test from C" | |
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
p = Person.new | |
p.refresh # => (...) | |
Person.start_trace | |
p.refresh # => (...) | |
# -> refresh: 0.500 s. | |
Person.end_trace | |
p.refresh # => (...) |
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
#!/usr/local/bin/ruby | |
require 'rubygems' | |
require 'call_stack' | |
require 'pp' | |
class Test | |
def foo | |
bar | |
end |
OlderNewer