- 1
- 2
- 3
def route_match? origin, destination
origin.iata == origin and destination.iata == destination
end
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 4
−102
def route_match? origin, destination
origin.iata == origin and destination.iata == destination
end
В классе конечно определены методы origin и destination
−116.6
class Vector
def -@
map(&:-@)
end
end
Код мой, говнокодом бы не назвал, но без улыбки точно не взглянешь на такое =)
(тут определение унарного минуса через вызов того же унарного минуса у всех элементов вектора, Кэп)
−121
def has_currency_rate?
val = false
if self.currency.id == self.client.company.currency.id or self.currency_rate.blank?
else
val = true
end
val
end
тяжело же жилось людям...
−130.2
class FinancialEventObserver < ActiveRecord::Observer
observe Payment, Invoice
def before_save(model)
event = nil
if model.class == Payment
if model.new_record?
event = FinancialEvent.new(:event => FinancialEvent::Event::PAYMENT_INVOICE,
:arguments => {:client_name => model.invoice.client.short_name, :invoice_number => model.invoice.invoice_number},
:company_id=>model.invoice.client.company.id)
end
elsif model.class == Invoice
i = Invoice.find_by_id model.id
if model.new_record? or i.status != model.status
if model.status == Invoice::Status::ESTIMATE
event = FinancialEvent.new(:event => FinancialEvent::Event::ESTIMATE_SEND,
:arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},
:company_id=>model.client.company.id)
elsif model.status == Invoice::Status::APPROVED
event = FinancialEvent.new(:event => FinancialEvent::Event::ESTIMATE_APPROVED,
:arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},
:company_id=>model.client.company.id)
elsif model.status == Invoice::Status::REJECTED
event = FinancialEvent.new(:event => FinancialEvent::Event::ESTIMATE_REJECTED,
:arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},
:company_id=>model.client.company.id)
elsif model.status == Invoice::Status::SEND
event = FinancialEvent.new(:event => FinancialEvent::Event::INVOICE_SEND,
:arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},
:company_id=>model.client.company.id)
end
elsif !model.new_record? and i.state != model.state
if model.state == Invoice::State::DELETED
event = FinancialEvent.new(:event => FinancialEvent::Event::INVOICE_DELETED,
:arguments => {:invoice_number => model.invoice_number},
:company_id=>model.client.company.id)
end
end
end
event.eventable = model.requester unless event.blank?
event.save unless event.blank?
end
def before_destroy(model)
if model.class == Payment
event = FinancialEvent.new(:event => FinancialEvent::Event::PAYMENT_DELETED,
:arguments => {:invoice_number => model.invoice.invoice_number},
:company_id=>model.invoice.client.company.id)
event.eventable = model.requester
event.save
end
end
end
о боже, зачем я открыл этот файл?