You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
785 B
27 lines
785 B
# Carrega as classes Message e LogEntry. O lazy loading do Rails gera
|
|
# problemas se voce definir varias classes por arquivos.
|
|
require "#{RAILS_ROOT}/app/models/message.rb"
|
|
require "#{RAILS_ROOT}/app/models/log_entry.rb"
|
|
|
|
class String
|
|
def is_numeric?
|
|
Float self rescue false
|
|
end
|
|
end
|
|
|
|
class Array
|
|
def add_condition! (condition, conjunction = 'AND')
|
|
if String === condition
|
|
add_condition!([condition])
|
|
elsif Hash === condition
|
|
add_condition!([condition.keys.map { |attr| "#{attr}=?" }.join(' AND ')] + condition.values)
|
|
elsif Array === condition
|
|
self[0] = "(#{self[0]}) #{conjunction} (#{condition.shift})" unless empty?
|
|
(self << condition).flatten!
|
|
else
|
|
raise "don't know how to handle this condition type"
|
|
end
|
|
self
|
|
end
|
|
end
|