Class: Drudgery::Extractors::ActiveRecordExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/drudgery/extractors/active_record_extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ ActiveRecordExtractor

Returns a new instance of ActiveRecordExtractor.



6
7
8
9
# File 'lib/drudgery/extractors/active_record_extractor.rb', line 6

def initialize(model)
  @model = model
  @name = "active_record:#{@model.name}"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/drudgery/extractors/active_record_extractor.rb', line 4

def name
  @name
end

Instance Method Details

#extractObject



11
12
13
14
15
16
17
18
19
# File 'lib/drudgery/extractors/active_record_extractor.rb', line 11

def extract
  index = 0

  @model.find_each do |record|
    yield [record.attributes, index]

    index += 1
  end
end

#record_countObject



21
22
23
# File 'lib/drudgery/extractors/active_record_extractor.rb', line 21

def record_count
  @record_count ||= @model.count
end