Class: Nfcollector::Partition
- Inherits:
-
Object
- Object
- Nfcollector::Partition
- Defined in:
- lib/nfcollector/partition.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#partition_id ⇒ Object
readonly
Returns the value of attribute partition_id.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Class Method Summary collapse
-
.get_partitioner(account_id, partition_key_index, headers) ⇒ Object
Instantiates a partitioner that will generate partitions of this type.
Instance Method Summary collapse
-
#add_row(row) ⇒ Object
Adds a row to the partition.
- #file_name ⇒ Object
-
#initialize(value, account_id, headers) ⇒ Partition
constructor
Create a new partition with the given values.
-
#keys ⇒ Hash
A set of keys used to generate the table for this partition.
-
#table_name ⇒ Object
Return the table name that should be used for the data in this partition.
Constructor Details
#initialize(value, account_id, headers) ⇒ Partition
Create a new partition with the given values
28 29 30 31 32 33 |
# File 'lib/nfcollector/partition.rb', line 28 def initialize(value, account_id, headers) @value = value @account_id = account_id @headers = headers @rows = [] end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
7 8 9 |
# File 'lib/nfcollector/partition.rb', line 7 def account_id @account_id end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/nfcollector/partition.rb', line 6 def headers @headers end |
#partition_id ⇒ Object (readonly)
Returns the value of attribute partition_id.
5 6 7 |
# File 'lib/nfcollector/partition.rb', line 5 def partition_id @partition_id end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
4 5 6 |
# File 'lib/nfcollector/partition.rb', line 4 def rows @rows end |
Class Method Details
.get_partitioner(account_id, partition_key_index, headers) ⇒ Object
Instantiates a partitioner that will generate partitions of this type
16 17 18 19 20 |
# File 'lib/nfcollector/partition.rb', line 16 def self.get_partitioner(account_id, partition_key_index, headers) Partitioner.new(self, account_id, partition_key_index).tap do |part| part.set_headers!(headers) end end |
Instance Method Details
#add_row(row) ⇒ Object
Adds a row to the partition
42 43 44 45 |
# File 'lib/nfcollector/partition.rb', line 42 def add_row(row) # TODO: Is there a cleaner way to do this?? @rows << [ @account_id ] + row end |
#file_name ⇒ Object
57 58 59 |
# File 'lib/nfcollector/partition.rb', line 57 def file_name @file_name ||= File.("#{table_name}_#{randstr}.copy", Configuration.output_dir) end |
#keys ⇒ Hash
Returns a set of keys used to generate the table for this partition.
63 64 65 |
# File 'lib/nfcollector/partition.rb', line 63 def keys raise NotImplemented end |
#table_name ⇒ Object
Return the table name that should be used for the data in this partition
51 52 53 54 55 |
# File 'lib/nfcollector/partition.rb', line 51 def table_name return @table_name if @table_name partition = ar_klass.partitions.find_or_create_for(keys) @table_name = partition.nil? ? ar_klass.table_name : partition.name end |