This file contains hidden or 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 QuotationWorkflow | |
def initialize(object) | |
@object = object | |
end | |
include Workflow | |
workflow do | |
state :created do |
This file contains hidden or 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 QuotationStatusPolicy | |
def initialize(quotation) | |
@quotation = quotation | |
end | |
# STATUSES | |
def unconfirmed? | |
[:mildly_interested, :negotiating].include?(quality) | |
end |
This file contains hidden or 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 Quotation | |
include DataMapper::Resource | |
# ...snip... | |
property :quoted_kms, Float | |
property :quoted_per_km, Float | |
property :quoted_price, Float | |
property :start_date, Date, :required => true | |
property :end_date, Date, :required => true |
This file contains hidden or 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 'forwardable' | |
class User | |
extend Forwardable | |
attr_accessor :view_delegate_class | |
def_delegators :view_delegate, :full_name | |
def initialize(first_name, last_name) | |
@first_name = first_name |
This file contains hidden or 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 FooController < ApplicationController | |
def index | |
search_params = (params[:quotation] || {}).select{|k,v| !v.blank?} | |
q = search_params.delete("user") | |
if q | |
q = "%#{q}%" | |
search_params[:intended_trip] = {:user => {:conditions => ['email ilike ? or first_name ilike ? or last_name ilike ? or mobile_number ilike ?', q, q, q, q]}} | |
end | |
if params[:all] | |
@quotations = Quotation.all(search_params) |
This file contains hidden or 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 QuotationsController < ApplicationController | |
def index | |
@params = QuotationsIndexParams.new(params) | |
(redirect_to request.referer || quotations_path, :error => "Bad Request", :status => 400 and return) unless @params.valid? | |
@quotations = Quotation.search(@params.search_params). | |
send(@params.scope, @params.scope_params). | |
sorted_by(@params.sort.to_sym). | |
page(params[:page]) | |
respond_to do |format| | |
format.html # index.html.erb |
This file contains hidden or 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 QuotationsIndexParams | |
include Virtus | |
include DataMapper::Validations | |
attribute :scope, String, :default => 'pending' | |
attribute :sort, String, :default => 'poolability' | |
attribute :quotation, Hash, :default => {} | |
attribute :date, Date | |
validates_within :scope, :set => [nil,'all','pending','to_call','to_pool', 'cabbed'] | |
This file contains hidden or 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
# let the argument errors come from the typecast. | |
# one should not worry about the class of the object, just its capabilities. | |
def initialize(hash = {}) | |
@name = hash[:name].to_s | |
@price = hash[:price].to_f | |
@quantity = Integer(hash[:quantity] || 1) | |
@list = List.new(hash[:list]) | |
end |
This file contains hidden or 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
# things controller | |
def update | |
@thing = Thing.find(params[:id]) | |
@thing.update_attributes(params[:thing]) | |
... | |
end |
This file contains hidden or 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
# POST {:id => <article_id>, :action => :update, :set_state => :published, :article => {:title => "foo"}} | |
def update | |
@article = Article.find(params[:id]) | |
@article.update!(params) # we call a method in Article which deals with our params | |
... | |
end |