Module: TableStructure::Schema::ClassMethods

Defined in:
lib/table_structure/schema/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#+(other) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/table_structure/schema/class_methods.rb', line 6

def +(other)
  unless ::TableStructure::Schema::Utils.schema_class?(other)
    raise ::TableStructure::Error, "Must be a schema class. #{other}"
  end

  self_class = self

  ::TableStructure::Schema.create_class do
    columns self_class
    columns other
  end
end

#merge(*others) ⇒ Object



19
20
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
49
# File 'lib/table_structure/schema/class_methods.rb', line 19

def merge(*others)
  others.each do |other|
    unless ::TableStructure::Schema::Utils.schema_class?(other)
      raise ::TableStructure::Error, "Must be a schema class. #{other}"
    end
  end

  schema_classes = [self, *others]

  ::TableStructure::Schema.create_class do
    @__column_definitions__ =
      schema_classes
      .map(&:column_definitions)
      .flatten

    @__context_builders__ =
      schema_classes
      .map(&:context_builders)
      .reduce({}, &:merge!)

    @__column_builders__ =
      schema_classes
      .map(&:column_builders)
      .reduce({}, &:merge!)

    @__row_builders__ =
      schema_classes
      .map(&:row_builders)
      .reduce({}, &:merge!)
  end
end