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 'rainbow' | |
def log(level, message) | |
Rails.logger.send level, message.foreground(color_for_level(level)) | |
if RAILS_ENV == 'development' | |
puts level.to_s.upcase " " message.foreground(color_for_level(level)) | |
end | |
end | |
def color_for_level(level) |
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 Time | |
def ceil(seconds = 60) | |
Time.at((self.to_f / seconds).ceil * seconds) | |
end | |
def floor(seconds = 60) | |
Time.at((self.to_f / seconds).floor * seconds) | |
end | |
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 Admin::AdminController < ActionController::Base | |
def self.simple_action(*actions) | |
actions.each {|action| class_eval("def #{action}; end")} | |
end | |
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 Settings < Settingslogic | |
source "#{Rails.root}/config/application.yml" | |
if Rails.env == 'development' | |
namespace 'development-' + Socket.gethostname.gsub(/\W/, '-').gsub(/[-]{2,}/, '-') | |
else | |
namespace Rails.env | |
end | |
# load local settings |
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 Application::Controller::Authlogic | |
def self.included(base) | |
base.extend Application::Controller::Authlogic::ClassMethods | |
end | |
module ClassMethods | |
end | |
def current_session(id=nil) | |
if User.session_ids.include?(id) |
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 ActionController::Base | |
def force_utf8_params | |
traverse = lambda do |object, block| | |
if object.kind_of?(Hash) | |
object.each_value { |o| traverse.call(o, block) } | |
elsif object.kind_of?(Array) | |
object.each { |o| traverse.call(o, block) } | |
else | |
block.call(object) |
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 Tour < Sequel::Model | |
many_to_one :vendor_pansion, | |
:dataset => proc{ Vendor::Pansion.where(:id => self.vendor_pansion_id) }, | |
:reciprocal => nil, :class => 'Vendor::Pansion', | |
:eager_loader => (proc do |opts| | |
opts[:rows].each{ |object| object.associations[:vendor_pansion] = nil } | |
Vendor::Pansion.where(:id => opts[:id_map].keys).each do |vendor_pansion| | |
if tours = opts[:id_map][vendor_pansion.id] | |
tours.each do |tour| |
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
@purchased_at = Date.civil(params[:purchased_at]["(1i)"].to_i, | |
params[:purchased_at]["(2i)"].to_i, | |
params[:purchased_at]["(3i)"].to_i) | |
@code = Partner::Code.lookup("Vendor", params[:code]) || build_vendor_code | |
@not_redeem = nil | |
@error_text = nil | |
@to_late = nil | |
if @code.nil? |
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 Fund::CreateCallForm < BaseForm | |
# your properties are here | |
# ... | |
validation do | |
configure do | |
config.messages_file = 'config/locales/dry-validation/errors.yml' | |
# don't forget about this option to be able to access your form object from your predicates | |
option :form | |
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 Fund::CreateCallForm < BaseForm | |
property :type | |
property :fund | |
validation do | |
required(:type) { filled? & included_in?(TRANSACTION_TYPES['Fund::Call']) } | |
end | |
validation if: -> (results) { rebalance? } do | |
required(:fund).filled |
OlderNewer