Class: Fx::Aggregate

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/fx-aggregate/aggregate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aggregate_row) ⇒ Aggregate

Returns a new instance of Aggregate.



8
9
10
11
12
# File 'lib/fx-aggregate/aggregate.rb', line 8

def initialize(aggregate_row)
  @name = aggregate_row.fetch("name")
  @arguments = aggregate_row.fetch("arguments", "")
  @definition = aggregate_row.except("name", "arguments")
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



5
6
7
# File 'lib/fx-aggregate/aggregate.rb', line 5

def arguments
  @arguments
end

#definitionObject (readonly)

Returns the value of attribute definition.



5
6
7
# File 'lib/fx-aggregate/aggregate.rb', line 5

def definition
  @definition
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/fx-aggregate/aggregate.rb', line 5

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
17
18
19
# File 'lib/fx-aggregate/aggregate.rb', line 14

def ==(other)
  other.is_a?(self.class) &&
    name == other.name &&
    arguments == other.arguments &&
    definition == other.definition
end

#to_schemaObject



21
22
23
24
25
26
27
28
29
# File 'lib/fx-aggregate/aggregate.rb', line 21

def to_schema
  <<-SCHEMA
  create_aggregate :#{name}, sql_definition: <<-\SQL
CREATE AGGREGATE #{name}(#{arguments})(
  #{options_for_create_statement.join(",\n").indent(6).lstrip}
);
  SQL
  SCHEMA
end