Class: Innodb::RecordDescriber
- Inherits:
-
Object
- Object
- Innodb::RecordDescriber
- Defined in:
- lib/innodb/record_describer.rb
Direct Known Subclasses
DataDictionary::SysColumnsPrimary, DataDictionary::SysFieldsPrimary, DataDictionary::SysIndexesPrimary, DataDictionary::SysTablesId, DataDictionary::SysTablesPrimary
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
Class Method Summary collapse
-
.add_static_field(group, name, type) ⇒ Object
An internal method wrapped with ‘key’ and ‘row’ helpers.
-
.key(name, *type) ⇒ Object
A ‘key’ method to be used from the DSL.
-
.row(name, *type) ⇒ Object
A ‘row’ method to be used from the DSL.
-
.static_description ⇒ Object
Internal method to initialize the class’s instance variable on access.
-
.type(type) ⇒ Object
A ‘type’ method to be used from the DSL.
Instance Method Summary collapse
-
#add_field(group, name, type) ⇒ Object
An internal method wrapped with ‘key’ and ‘row’ helpers.
- #field_names ⇒ Object
- #generate_class(name = "Describer_#{object_id}") ⇒ Object
-
#initialize ⇒ RecordDescriber
constructor
A new instance of RecordDescriber.
-
#key(name, *type) ⇒ Object
Add a key column to the record description.
-
#row(name, *type) ⇒ Object
Add a row (non-key) column to the record description.
-
#type(type) ⇒ Object
Set the type of this record (:clustered or :secondary).
Constructor Details
#initialize ⇒ RecordDescriber
Returns a new instance of RecordDescriber.
86 87 88 89 90 |
# 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 |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
84 85 86 |
# File 'lib/innodb/record_describer.rb', line 84 def description @description end |
Class Method Details
.add_static_field(group, name, type) ⇒ Object
An internal method wrapped with ‘key’ and ‘row’ helpers.
70 71 72 |
# 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) ⇒ Object
A ‘key’ method to be used from the DSL.
75 76 77 |
# File 'lib/innodb/record_describer.rb', line 75 def self.key(name, *type) add_static_field :key, name, type end |
.row(name, *type) ⇒ Object
A ‘row’ method to be used from the DSL.
80 81 82 |
# File 'lib/innodb/record_describer.rb', line 80 def self.row(name, *type) add_static_field :row, name, type end |
.static_description ⇒ Object
Internal method to initialize the class’s instance variable on access.
60 61 62 |
# File 'lib/innodb/record_describer.rb', line 60 def self.static_description @static_description ||= { type: nil, key: [], row: [] } end |
.type(type) ⇒ Object
A ‘type’ method to be used from the DSL.
65 66 67 |
# File 'lib/innodb/record_describer.rb', line 65 def self.type(type) static_description[:type] = type end |
Instance Method Details
#add_field(group, name, type) ⇒ Object
An internal method wrapped with ‘key’ and ‘row’ helpers.
98 99 100 |
# File 'lib/innodb/record_describer.rb', line 98 def add_field(group, name, type) description[group] << { name: name, type: type } end |
#field_names ⇒ Object
112 113 114 115 116 117 118 |
# 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_#{object_id}") ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/innodb/record_describer.rb', line 120 def generate_class(name = "Describer_#{object_id}") str = "class #{name}\n".dup str << " type %s\n" % [ description[:type].inspect, ] %i[key row].each do |group| description[group].each do |item| str << " %s %s, %s\n" % [ group, item[:name].inspect, item[:type].map(&:inspect).join(", "), ] end end str << "end\n" str end |
#key(name, *type) ⇒ Object
Add a key column to the record description.
103 104 105 |
# File 'lib/innodb/record_describer.rb', line 103 def key(name, *type) add_field :key, name, type end |
#row(name, *type) ⇒ Object
Add a row (non-key) column to the record description.
108 109 110 |
# File 'lib/innodb/record_describer.rb', line 108 def row(name, *type) add_field :row, name, type end |
#type(type) ⇒ Object
Set the type of this record (:clustered or :secondary).
93 94 95 |
# File 'lib/innodb/record_describer.rb', line 93 def type(type) description[:type] = type end |