Class: Purview::Tables::Base
Direct Known Subclasses
Raw
Instance Attribute Summary collapse
Instance Method Summary
collapse
#logger, #logger_opts, #logger_type, #with_context_logging
Constructor Details
#initialize(name, opts = {}) ⇒ Base
Returns a new instance of Base.
6
7
8
9
|
# File 'lib/purview/tables/base.rb', line 6
def initialize(name, opts={})
@name = name
@opts = opts
end
|
Instance Attribute Details
Returns the value of attribute database.
4
5
6
|
# File 'lib/purview/tables/base.rb', line 4
def database
@database
end
|
Returns the value of attribute name.
4
5
6
|
# File 'lib/purview/tables/base.rb', line 4
def name
@name
end
|
Instance Method Details
#column_names ⇒ Object
15
16
17
|
# File 'lib/purview/tables/base.rb', line 15
def column_names
columns.map(&:name)
end
|
11
12
13
|
# File 'lib/purview/tables/base.rb', line 11
def columns
opts[:columns]
end
|
#columns_by_name ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/purview/tables/base.rb', line 19
def columns_by_name
{}.tap do |result|
columns.each do |column|
result[column.name] = column
end
end
end
|
#columns_of_type(type) ⇒ Object
27
28
29
|
# File 'lib/purview/tables/base.rb', line 27
def columns_of_type(type)
columns.select { |column| column.is_a?(type) }
end
|
#created_timestamp_column ⇒ Object
31
32
33
|
# File 'lib/purview/tables/base.rb', line 31
def created_timestamp_column
columns_of_type(Purview::Columns::CreatedTimestamp).first
end
|
#data_columns ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/purview/tables/base.rb', line 35
def data_columns
columns - [
created_timestamp_column,
id_column,
updated_timestamp_column,
]
end
|
#id_column ⇒ Object
48
49
50
|
# File 'lib/purview/tables/base.rb', line 48
def id_column
columns_of_type(Purview::Columns::Id).first
end
|
#indexed_columns ⇒ Object
52
53
54
55
56
57
|
# File 'lib/purview/tables/base.rb', line 52
def indexed_columns
(opts[:indexed_columns] || []).tap do |indexed_columns|
indexed_columns << [created_timestamp_column]
indexed_columns << [updated_timestamp_column]
end
end
|
#starting_timestamp ⇒ Object
59
60
61
|
# File 'lib/purview/tables/base.rb', line 59
def starting_timestamp
opts[:starting_timestamp]
end
|
#sync(connection, window) ⇒ Object
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/purview/tables/base.rb', line 63
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_name ⇒ Object
74
75
76
|
# File 'lib/purview/tables/base.rb', line 74
def temporary_name
"#{name}_#{Time.now.utc.to_i}"
end
|
#updated_timestamp_column ⇒ Object
78
79
80
|
# File 'lib/purview/tables/base.rb', line 78
def updated_timestamp_column
columns_of_type(Purview::Columns::UpdatedTimestamp).first
end
|
#window_size ⇒ Object
82
83
84
|
# File 'lib/purview/tables/base.rb', line 82
def window_size
opts[:window_size] || (60 * 60)
end
|