Skip to content

Instantly share code, notes, and snippets.

View mirrec's full-sized avatar

Miroslav Hettes mirrec

  • Bratislava, Slovakia
View GitHub Profile
@mirrec
mirrec / due_date_calculator.rb
Created March 4, 2014 12:25
extracting pure ruby object from model
require "active_support/time"
class DueDateCalculator
def initialize(season)
@season = season
end
def calculate
@season.upcoming_round.start_date - 1.day
end
@mirrec
mirrec / season_ticket.rb
Created March 4, 2014 12:25
Avoid callbacks hell, by creating service objects
class SeasonTicket < ActiveRecord::Base
# ...
def order!
self.price = calculate_price
self.status = :ordered
save!
self
end
# ...
end
@mirrec
mirrec / 1_integration_test_in_comments_spec.rb
Created March 4, 2014 12:26
Code snippets for rails workflow
describe "Amazon bounce handling process" do
# We have subscriptions on email "[email protected]" in different clients
# When last email to him was returned with "permanent failure"
# Then all subscription on email "[email protected]" are marked as bounced
end
@mirrec
mirrec / season_manager.rb
Created March 4, 2014 12:37
Use exception for exceptional cases, and handle them properly in application
class SeasonManager
NoSeason = Class.new(StandardError)
# actual league that we players are playing, if we are in the right date window
def self.active
Season.active
end
# in season break, it return next season
def self.upcoming