Class: Egis::TableSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/egis/table_schema.rb

Overview

Provides DSL for defining table schemas.

Examples:

Table schema definition

schema = Egis::TableSchema.define do
  column :id, :int
  column :message, :string

  partition :country, :string
  partition :type, :int
end

Defined Under Namespace

Classes: Column

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ TableSchema

Returns a new instance of TableSchema.



29
30
31
32
33
# File 'lib/egis/table_schema.rb', line 29

def initialize(&block)
  @columns = []
  @partitions = []
  instance_eval(&block)
end

Instance Attribute Details

#columnsEgis::TableSchema::Column (readonly)



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/egis/table_schema.rb', line 21

class TableSchema
  ##
  # @return [Egis::TableSchema]

  def self.define(&block)
    new(&block)
  end

  def initialize(&block)
    @columns = []
    @partitions = []
    instance_eval(&block)
  end

  attr_reader :columns, :partitions

  private

  def column(name, type)
    @columns << Column.new(name, type)
  end

  def partition(name, type)
    @partitions << Column.new(name, type)
  end

  Column = Struct.new(:name, :type)
end

#partitionsEgis::TableSchema::Column (readonly)



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/egis/table_schema.rb', line 21

class TableSchema
  ##
  # @return [Egis::TableSchema]

  def self.define(&block)
    new(&block)
  end

  def initialize(&block)
    @columns = []
    @partitions = []
    instance_eval(&block)
  end

  attr_reader :columns, :partitions

  private

  def column(name, type)
    @columns << Column.new(name, type)
  end

  def partition(name, type)
    @partitions << Column.new(name, type)
  end

  Column = Struct.new(:name, :type)
end

Class Method Details

.define(&block) ⇒ Egis::TableSchema

Returns:



25
26
27
# File 'lib/egis/table_schema.rb', line 25

def self.define(&block)
  new(&block)
end