Class: GroongaSchema::Table
- Inherits:
-
Object
- Object
- GroongaSchema::Table
- Defined in:
- lib/groonga-schema/table.rb
Defined Under Namespace
Classes: CommandApplier
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#default_tokenizer ⇒ Object
Returns the value of attribute default_tokenizer.
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#key_type ⇒ Object
Returns the value of attribute key_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#normalizer ⇒ Object
Returns the value of attribute normalizer.
-
#reference_key_type ⇒ Object
writeonly
Sets the attribute reference_key_type.
-
#related_columns ⇒ Object
Returns the value of attribute related_columns.
-
#related_tables ⇒ Object
Returns the value of attribute related_tables.
-
#token_filters ⇒ Object
Returns the value of attribute token_filters.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value_type ⇒ Object
Returns the value of attribute value_type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #apply_command(command) ⇒ Object
-
#initialize(name) ⇒ Table
constructor
A new instance of Table.
- #reference_key_type? ⇒ Boolean
- #to_create_groonga_command ⇒ Object
- #to_migrate_finish_groonga_commands ⇒ Object
- #to_migrate_start_groonga_commands ⇒ Object
- #to_remove_groonga_command ⇒ Object
Constructor Details
#initialize(name) ⇒ Table
Returns a new instance of Table.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/groonga-schema/table.rb', line 31 def initialize(name) @name = name @type = :no_key @flags = [] @key_type = nil @value_type = nil @default_tokenizer = nil @normalizer = nil @token_filters = [] @reference_key_type = false @columns = [] @related_tables = [] @related_columns = [] end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
28 29 30 |
# File 'lib/groonga-schema/table.rb', line 28 def columns @columns end |
#default_tokenizer ⇒ Object
Returns the value of attribute default_tokenizer.
24 25 26 |
# File 'lib/groonga-schema/table.rb', line 24 def default_tokenizer @default_tokenizer end |
#flags ⇒ Object
Returns the value of attribute flags.
21 22 23 |
# File 'lib/groonga-schema/table.rb', line 21 def flags @flags end |
#key_type ⇒ Object
Returns the value of attribute key_type.
22 23 24 |
# File 'lib/groonga-schema/table.rb', line 22 def key_type @key_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/groonga-schema/table.rb', line 19 def name @name end |
#normalizer ⇒ Object
Returns the value of attribute normalizer.
25 26 27 |
# File 'lib/groonga-schema/table.rb', line 25 def normalizer @normalizer end |
#reference_key_type=(value) ⇒ Object (writeonly)
Sets the attribute reference_key_type
27 28 29 |
# File 'lib/groonga-schema/table.rb', line 27 def reference_key_type=(value) @reference_key_type = value end |
#related_columns ⇒ Object
Returns the value of attribute related_columns.
30 31 32 |
# File 'lib/groonga-schema/table.rb', line 30 def @related_columns end |
#related_tables ⇒ Object
Returns the value of attribute related_tables.
29 30 31 |
# File 'lib/groonga-schema/table.rb', line 29 def @related_tables end |
#token_filters ⇒ Object
Returns the value of attribute token_filters.
26 27 28 |
# File 'lib/groonga-schema/table.rb', line 26 def token_filters @token_filters end |
#type ⇒ Object
Returns the value of attribute type.
20 21 22 |
# File 'lib/groonga-schema/table.rb', line 20 def type @type end |
#value_type ⇒ Object
Returns the value of attribute value_type.
23 24 25 |
# File 'lib/groonga-schema/table.rb', line 23 def value_type @value_type end |
Instance Method Details
#==(other) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/groonga-schema/table.rb', line 55 def ==(other) return false unless other.is_a?(self.class) @name == other.name and @type == other.type and @flags.sort == other.flags.sort and @key_type == other.key_type and @value_type == other.value_type and @default_tokenizer == other.default_tokenizer and @normalizer == other.normalizer and @token_filters == other.token_filters end |
#apply_command(command) ⇒ Object
50 51 52 53 |
# File 'lib/groonga-schema/table.rb', line 50 def apply_command(command) applier = CommandApplier.new(self, command) applier.apply end |
#reference_key_type? ⇒ Boolean
46 47 48 |
# File 'lib/groonga-schema/table.rb', line 46 def reference_key_type? @reference_key_type end |
#to_create_groonga_command ⇒ Object
68 69 70 |
# File 'lib/groonga-schema/table.rb', line 68 def to_create_groonga_command table_create_command(@name) end |
#to_migrate_finish_groonga_commands ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/groonga-schema/table.rb', line 96 def to_migrate_finish_groonga_commands commands = [] sorted_columns = @columns.sort_by(&:name) sorted_columns.each do |column| next unless column.type == :index commands << column.to_create_groonga_command end commands << table_remove_command(old_name) commands end |
#to_migrate_start_groonga_commands ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/groonga-schema/table.rb', line 76 def to_migrate_start_groonga_commands commands = [] commands << table_create_command(new_name) if @columns.empty? commands << table_copy_command(@name, new_name) else sorted_columns = @columns.sort_by(&:name) sorted_columns.each do |column| next if column.type == :index new_column = Column.new(new_name, column.name) new_column.apply_column(column) commands << new_column.to_create_groonga_command commands << column.to_copy_groonga_command(new_name, column.name) end end commands << table_rename_command(@name, old_name) commands << table_rename_command(new_name, @name) commands end |
#to_remove_groonga_command ⇒ Object
72 73 74 |
# File 'lib/groonga-schema/table.rb', line 72 def to_remove_groonga_command table_remove_command(@name) end |