lib/beso/job.rb in beso-0.2.1 vs lib/beso/job.rb in beso-0.3.0
- old
+ new
@@ -3,10 +3,11 @@
def initialize( event, options )
@event = event.to_sym
@title = options.delete( :event ) || @event.to_s.titleize
@table = options.delete( :table )
@since = options.delete( :since )
+ @scope = options.delete( :scope ) || lambda { self }
@props = { }
@extra = options
end
attr_reader :event
@@ -26,12 +27,12 @@
def to_csv( options={} )
raise MissingIdentityError if @identity.nil?
raise MissingTimestampError if @timestamp.nil?
- @since ||= options.delete :since
+ @since ||= options.delete( :since ) || first_timestamp
- relation = model_class.where( "#{@timestamp} >= ?", @since || first_timestamp )
+ relation = model_class.instance_exec( &@scope ).where( "#{@timestamp} >= ?", @since )
return nil if relation.empty?
Beso::CSV.generate( @extra.merge( options ) ) do |csv|
csv << ( required_headers + custom_headers )