Class: Beso::Job
- Inherits:
-
Object
- Object
- Beso::Job
- Defined in:
- lib/beso/job.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
Instance Method Summary collapse
- #first_timestamp ⇒ Object
- #identity(value = nil, &block) ⇒ Object
-
#initialize(event, options) ⇒ Job
constructor
A new instance of Job.
- #last_timestamp ⇒ Object
- #prop(name, value = nil, &block) ⇒ Object
- #timestamp(value) ⇒ Object
- #to_csv(options = {}) ⇒ Object
Constructor Details
#initialize(event, options) ⇒ Job
Returns a new instance of Job.
3 4 5 6 7 8 9 10 11 |
# File 'lib/beso/job.rb', line 3 def initialize( event, ) @event = event.to_sym @title = .delete( :event ) || @event.to_s.titleize @table = .delete( :table ) @since = .delete( :since ) @scope = .delete( :scope ) || lambda { self } @props = { } @extra = end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
12 13 14 |
# File 'lib/beso/job.rb', line 12 def event @event end |
Instance Method Details
#first_timestamp ⇒ Object
49 50 51 |
# File 'lib/beso/job.rb', line 49 def model_class.minimum @timestamp end |
#identity(value = nil, &block) ⇒ Object
14 15 16 |
# File 'lib/beso/job.rb', line 14 def identity( value=nil, &block ) @identity = value || block end |
#last_timestamp ⇒ Object
53 54 55 |
# File 'lib/beso/job.rb', line 53 def model_class.maximum @timestamp end |
#prop(name, value = nil, &block) ⇒ Object
23 24 25 26 |
# File 'lib/beso/job.rb', line 23 def prop( name, value=nil, &block ) raise TooManyPropertiesError if @props.length == 10 @props[ name.to_sym ] = value || block || name.to_sym end |
#timestamp(value) ⇒ Object
18 19 20 21 |
# File 'lib/beso/job.rb', line 18 def ( value ) raise InvalidTimestampError unless value.is_a?(Symbol) @timestamp = value end |
#to_csv(options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/beso/job.rb', line 28 def to_csv( ={} ) raise MissingIdentityError if @identity.nil? raise MissingTimestampError if @timestamp.nil? @since ||= .delete( :since ) || condition = "#{@table}.#{@timestamp} >= ?" relation = model_class.instance_exec( &@scope ).where( condition, @since ) return nil if relation.empty? Beso::CSV.generate( @extra.merge( ) ) do |csv| csv << ( required_headers + custom_headers ) relation.each do |model| csv << ( required_columns( model ) + custom_columns( model ) ) end end end |