class Innodb::RecordDescriber

Attributes

description[RW]

Public Class Methods

add_static_field(group, name, type) click to toggle source

An internal method wrapped with ‘key’ and ‘row’ helpers.

# File lib/innodb/record_describer.rb, line 70
def self.add_static_field(group, name, type)
  static_description[group] << { name: name, type: type }
end
key(name, *type) click to toggle source

A ‘key’ method to be used from the DSL.

# File lib/innodb/record_describer.rb, line 75
def self.key(name, *type)
  add_static_field :key, name, type
end
new() click to toggle source
# File lib/innodb/record_describer.rb, line 86
def initialize
  @description = self.class.static_description.dup
  @description[:key] = @description[:key].dup
  @description[:row] = @description[:row].dup
end
row(name, *type) click to toggle source

A ‘row’ method to be used from the DSL.

# File lib/innodb/record_describer.rb, line 80
def self.row(name, *type)
  add_static_field :row, name, type
end
static_description() click to toggle source

Internal method to initialize the class’s instance variable on access.

# File lib/innodb/record_describer.rb, line 60
def self.static_description
  @static_description ||= { type: nil, key: [], row: [] }
end
type(type) click to toggle source

A ‘type’ method to be used from the DSL.

# File lib/innodb/record_describer.rb, line 65
def self.type(type)
  static_description[:type] = type
end

Public Instance Methods

add_field(group, name, type) click to toggle source

An internal method wrapped with ‘key’ and ‘row’ helpers.

# File lib/innodb/record_describer.rb, line 98
def add_field(group, name, type)
  description[group] << { name: name, type: type }
end
field_names() click to toggle source
# File lib/innodb/record_describer.rb, line 112
def field_names
  names = []
  %i[key row].each do |group|
    names += description[group].map { |n| n[:name] }
  end
  names
end
generate_class(name = "Describer_ click to toggle source
# File lib/innodb/record_describer.rb, line 120
def generate_class(name = "Describer_#{object_id}")
  str = "class #{name}\n".dup
  str << format("  type %s\n", description[:type].inspect)
  %i[key row].each do |group|
    description[group].each do |item|
      str << format(
        "  %s %s, %s\n",
        group,
        item[:name].inspect,
        item[:type].map(&:inspect).join(", ")
      )
    end
  end
  str << "end\n"
  str
end
key(name, *type) click to toggle source

Add a key column to the record description.

# File lib/innodb/record_describer.rb, line 103
def key(name, *type)
  add_field :key, name, type
end
row(name, *type) click to toggle source

Add a row (non-key) column to the record description.

# File lib/innodb/record_describer.rb, line 108
def row(name, *type)
  add_field :row, name, type
end
type(type) click to toggle source

Set the type of this record (:clustered or :secondary).

# File lib/innodb/record_describer.rb, line 93
def type(type)
  description[:type] = type
end