Module: Urge::Persistence::ActiveRecordPersistence::ClassMethods

Defined in:
lib/urge/persistence/active_record_persistence.rb

Instance Method Summary collapse

Instance Method Details

#urge_all!(name) ⇒ Object

def self.retailer( criteria ) matches = joins( :retailer )

Can specify name and account code explicitly

[:name, :account_code].each do |attribute| matches = matches.where( Retailer.arel_table.matches("%#criteria[attribute]%" ) ) unless criteria.blank? end

Can specify general criteria

if !criteria.blank? restriction = nil [:name, :account_code].each do |attribute| predicate = Retailer.arel_table.matches( "%#criteria[:retailer]%" ) restriction = restriction ? restriction.or( predicate ) : predicate end matches = matches.where( restriction ) end matches end



39
40
41
# File 'lib/urge/persistence/active_record_persistence.rb', line 39

def urge_all!( name )
  urgent( name ).each { |u| u.urge!( name ) }
end

#urgent(name, at = DateTime.now) ⇒ Object

AR finder



14
15
16
17
18
# File 'lib/urge/persistence/active_record_persistence.rb', line 14

def urgent( name, at = DateTime.now )
  options = urge_schedules[name]
  raise 'Unknown schedule' unless options
  where( "#{urge_attr_name(name)} < ?", at )
end