Skip to content

Instantly share code, notes, and snippets.

@svs
svs / gist:5508369
Last active December 16, 2015 22:39
EuRuKo Leaderboard
Grzegorz Witek = 104
Dirkjan Bussink = 84
Konstantin Tennhard = 74
Pat Shaughnessy = 74
Benjamin Smith = 72
Daniel Lobato García = 59
Josep M. Bach = 56
Javier Ramírez = 56
Alexandre de Oliveira = 52
Alexey Vasiliev = 49
class VendorBooker
# This class is responsible for calling the appropriate translation mechanism to convert a CRM Trip
# into the appropriate format to book
#
# It also translates the response into a CRM Booking object to persist to the database
def initialize(trip, vendor, credentials)
@trip = trip
@vendor = vendor
@svs
svs / trip_booker.rb
Last active December 11, 2015 02:39
class TripBooker
# Given a trip and a list of vendors, this class makes bookings for all the vendors
def initialize(trip, vendors = :all)
@trip = trip
@vendors = VendorSelector.new(vendors).all
@credentials = CredentialSelector.get_available_credentials
end
class ActivityLog
include DataMapper::Resource
property :id, Serial
property :type, Discriminator
property :model_id, Integer
property :event, String
class Foo
include DataMapper::Resource
include ActivityLogger
log_with :foo_activity_log
# ...snip ...
end
module ActivityLogger
include ActiveSupport
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def log_with(model_name, options = {})
class FoosController < ActionController::Base
# ..snip ..
def create
@foo = Foo.new(params[:foo])
@foo.save_with_log(current_user)
# ...
end
class ActivityLog
include DataMapper::Resource
property :id, Serial
property :type, Discriminator
property :model_id, Integer
property :event, String
@svs
svs / foo.rb
Last active December 10, 2015 14:58
# following are extracts from the relevant classes and not real Ruby code.
class Foo
belongs_to :user
end
class User
has n, :foos
end
class Quotation
# ...snip...
# methods to be forwarded to the status policy class
def self.status_policy_methods
[:unconfirmed?, :expirable?, :approvable?, :rejectable?, :poolable?, :on_holdable?, :payable?, :callbackable?, :sendable?]
end
# methods to be forwarded to workflow class