Class: Gitlab::Database::Aggregation::PartDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/aggregation/part_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, expression = nil, secondary_expression: nil, description: nil, formatter: nil) ⇒ PartDefinition

Returns a new instance of PartDefinition.

Parameters:

  • name (Symbol)

    the name of the part

  • type (Symbol)

    part data type (integer, float, string etc)

  • expression (Proc) (defaults to: nil)

    Arel expression for the part. Implementation specific

  • secondary_expression (Proc) (defaults to: nil)

    Secondary arel expression for the part. Implementation specific

  • description (String) (defaults to: nil)

    Description of the part

  • formatter (Proc) (defaults to: nil)

    formatting block to apply after DB loading.



15
16
17
18
19
20
21
22
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 15

def initialize(name, type, expression = nil, secondary_expression: nil, description: nil, formatter: nil, **)
  @name = name
  @type = type
  @expression = expression
  @secondary_expression = secondary_expression
  @description = description
  @formatter = formatter
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 7

def description
  @description
end

#expressionObject (readonly)

Returns the value of attribute expression.



7
8
9
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 7

def expression
  @expression
end

#formatterObject (readonly)

Returns the value of attribute formatter.



7
8
9
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 7

def formatter
  @formatter
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 7

def name
  @name
end

#secondary_expressionObject (readonly)

Returns the value of attribute secondary_expression.



7
8
9
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 7

def secondary_expression
  @secondary_expression
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 7

def type
  @type
end

Instance Method Details

#format_value(val) ⇒ Object



24
25
26
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 24

def format_value(val)
  formatter ? formatter.call(val) : val
end

#identifierObject

part identifier. Must be unique across all part definitions.



33
34
35
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 33

def identifier
  name
end

#instance_key(_configuration) ⇒ Object

Returns unique key for each part configuration in given request. For definitions without configration the key is static For definitions with configuration the key depends on the configuration parameters Must be unique across all QueryPlan parts.



42
43
44
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 42

def instance_key(_configuration)
  identifier.to_s
end

#validate_part(_plan_part) ⇒ Object



28
29
30
# File 'lib/gitlab/database/aggregation/part_definition.rb', line 28

def validate_part(_plan_part)
  # no-op by default
end