Class: Purview::Tables::BaseSyncable

Inherits:
Base show all
Defined in:
lib/purview/tables/base_syncable.rb

Direct Known Subclasses

Raw

Instance Attribute Summary

Attributes inherited from Base

#columns, #database, #indices, #name

Instance Method Summary collapse

Methods inherited from Base

#column_names, #columns_by_name, #columns_by_source_name, #initialize

Methods included from Mixins::Logger

#logger, #logger_opts, #logger_type, #with_context_logging

Methods included from Mixins::Helpers

#blank?, #coalesced, #filter_blank_values, #filter_nil_values, #present?, #timestamp, #with_timestamp, #zero?

Constructor Details

This class inherits a constructor from Purview::Tables::Base

Instance Method Details

#created_timestamp_columnObject



4
5
6
# File 'lib/purview/tables/base_syncable.rb', line 4

def created_timestamp_column
  column_from_opts_of_type(Purview::Columns::CreatedTimestamp) or raise %{Must specify a column of type: "#{Purview::Columns::CreatedTimestamp}"}
end

#created_timestamp_indexObject



8
9
10
# File 'lib/purview/tables/base_syncable.rb', line 8

def created_timestamp_index
  Purview::Indices::Simple.new(created_timestamp_column)
end

#id_columnObject



12
13
14
# File 'lib/purview/tables/base_syncable.rb', line 12

def id_column
  column_from_opts_of_type(Purview::Columns::Id) or raise %{Must specify a column of type: "#{Purview::Columns::Id}"}
end

#sync(connection, window) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/purview/tables/base_syncable.rb', line 16

def sync(connection, window)
  raw_data = puller.pull(window)
  parser.validate(raw_data)
  parsed_data = parser.parse(raw_data)
  loader.load(
    connection,
    parsed_data,
    window
  )
end

#temporary_nameObject



27
28
29
# File 'lib/purview/tables/base_syncable.rb', line 27

def temporary_name
  "#{name}_#{timestamp.to_i}"
end

#updated_timestamp_columnObject



31
32
33
# File 'lib/purview/tables/base_syncable.rb', line 31

def updated_timestamp_column
  column_from_opts_of_type(Purview::Columns::UpdatedTimestamp) or raise %{Must specify a column of type: "#{Purview::Columns::UpdatedTimestamp}"}
end

#updated_timestamp_indexObject



35
36
37
# File 'lib/purview/tables/base_syncable.rb', line 35

def updated_timestamp_index
  Purview::Indices::Simple.new(updated_timestamp_column)
end

#window_sizeObject



39
40
41
# File 'lib/purview/tables/base_syncable.rb', line 39

def window_size
  opts[:window_size] || (60 * 60)
end