Class: Purview::Tables::Base

Inherits:
Object
  • Object
show all
Includes:
Mixins::Helpers, Mixins::Logger
Defined in:
lib/purview/tables/base.rb

Direct Known Subclasses

BaseSyncable, TableMetadata

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#initialize(name, opts = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/purview/tables/base.rb', line 6

def initialize(name, opts={})
  @name = name.to_sym
  @opts = opts
  @database = database_opt
  @columns = Set.new.tap do |result|
    (default_columns + columns_opt).each do |column|
      column.table = self if result.add?(column)
    end
  end
  @indices = Set.new.tap do |result|
    (default_indices + indices_opt).each do |index|
      index.table = self if result.add?(index)
    end
  end
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



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

def columns
  @columns
end

#databaseObject

Returns the value of attribute database.



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

def database
  @database
end

#indicesObject (readonly)

Returns the value of attribute indices.



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

def indices
  @indices
end

#nameObject (readonly)

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_namesObject



22
23
24
# File 'lib/purview/tables/base.rb', line 22

def column_names
  columns.map(&:name)
end

#columns_by_nameObject



26
27
28
29
30
31
# File 'lib/purview/tables/base.rb', line 26

def columns_by_name
  columns.reduce({}) do |memo, column|
    memo[column.name] = column
    memo
  end
end

#columns_by_source_nameObject



33
34
35
36
37
38
# File 'lib/purview/tables/base.rb', line 33

def columns_by_source_name
  columns.reduce({}) do |memo, column|
    memo[column.source_name] = column
    memo
  end
end