Class: RelationalExporter::CsvBuilder
- Inherits:
-
Object
- Object
- RelationalExporter::CsvBuilder
- Includes:
- Celluloid, Celluloid::Logger
- Defined in:
- lib/relational_exporter/csv_builder.rb
Instance Attribute Summary collapse
-
#end_index ⇒ Object
Returns the value of attribute end_index.
-
#queue ⇒ Object
Returns the value of attribute queue.
Instance Method Summary collapse
- #actor_died(actor, reason) ⇒ Object
-
#initialize(file_path = nil) ⇒ CsvBuilder
constructor
A new instance of CsvBuilder.
- #remaining ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(file_path = nil) ⇒ CsvBuilder
Returns a new instance of CsvBuilder.
15 16 17 18 19 20 21 |
# File 'lib/relational_exporter/csv_builder.rb', line 15 def initialize(file_path=nil) @header_row = [] @index = 0 @end_index = nil @queue = {} @file_path = file_path end |
Instance Attribute Details
#end_index ⇒ Object
Returns the value of attribute end_index.
8 9 10 |
# File 'lib/relational_exporter/csv_builder.rb', line 8 def end_index @end_index end |
#queue ⇒ Object
Returns the value of attribute queue.
8 9 10 |
# File 'lib/relational_exporter/csv_builder.rb', line 8 def queue @queue end |
Instance Method Details
#actor_died(actor, reason) ⇒ Object
11 12 13 |
# File 'lib/relational_exporter/csv_builder.rb', line 11 def actor_died(actor, reason) warn "Oh no! #{actor.inspect} has died because of a #{reason.class}" unless reason.nil? end |
#remaining ⇒ Object
49 50 51 |
# File 'lib/relational_exporter/csv_builder.rb', line 49 def remaining @end_index - @index if @end_index end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/relational_exporter/csv_builder.rb', line 23 def start csv_args = @file_path.blank? ? STDOUT : @file_path = {headers: true} if @file_path.blank? csv_method = :instance csv_args = [STDOUT, ] else csv_method = :open csv_args = [@file_path, 'wb', ] end ::CSV.send(csv_method, *csv_args) do |csv| until @index == @end_index if row = @queue.delete(@index) write_row(row, csv) @index += 1 else sleep 1 end end end true end |