Class: RStore::Storage
- Includes:
- HelperMethods
- Defined in:
- lib/rstore/storage.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#db ⇒ Object
Returns the value of attribute db.
-
#prepared_data ⇒ Object
Returns the value of attribute prepared_data.
-
#primary_key ⇒ Object
Returns the value of attribute primary_key.
-
#state ⇒ Object
Returns the value of attribute state.
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
- #column_names ⇒ Object
-
#initialize(data_object, database, table_name) ⇒ Storage
constructor
A new instance of Storage.
- #insert ⇒ Object
- #prepare_data ⇒ Object
Methods included from HelperMethods
Constructor Details
#initialize(data_object, database, table_name) ⇒ Storage
Returns a new instance of Storage.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rstore/storage.rb', line 17 def initialize data_object, database, table_name state = data_object.state raise InvalidStateError, "#{state.inspect} is not a valid state on initialization for class Storage" unless state == :converted @state = state @data = data_object.clone @db = database @table = table_name @schema = @db.schema(@table) @primary_key = p_key @schema @prepared_data = prepare_data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
13 14 15 |
# File 'lib/rstore/storage.rb', line 13 def data @data end |
#db ⇒ Object
Returns the value of attribute db.
13 14 15 |
# File 'lib/rstore/storage.rb', line 13 def db @db end |
#prepared_data ⇒ Object
Returns the value of attribute prepared_data.
13 14 15 |
# File 'lib/rstore/storage.rb', line 13 def prepared_data @prepared_data end |
#primary_key ⇒ Object
Returns the value of attribute primary_key.
13 14 15 |
# File 'lib/rstore/storage.rb', line 13 def primary_key @primary_key end |
#state ⇒ Object
Returns the value of attribute state.
14 15 16 |
# File 'lib/rstore/storage.rb', line 14 def state @state end |
#table ⇒ Object
Returns the value of attribute table.
13 14 15 |
# File 'lib/rstore/storage.rb', line 13 def table @table end |
Instance Method Details
#column_names ⇒ Object
30 31 32 33 34 |
# File 'lib/rstore/storage.rb', line 30 def column_names @schema.map do |(col_name, col_properties)| col_name unless col_name == @primary_key end.compact end |
#insert ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rstore/storage.rb', line 45 def insert dataset = @db[@table] begin @db.transaction do @prepared_data.each_with_index do |row, row_index| @row_index = row_index dataset.insert(row) # Sequel often only throws an exception when retrieving an incorrect record, # The following therefore is to catch invalid data of data types that are # not checked by RStore::Converter dataset.order(@primary_key).last end end rescue Exception => e logger = Logger.new(@data) logger.log(:store, e, row: @row_index) logger.error end @state = :stored @state end |