Class: Groonga::Schema::IndexColumnDefinition
- Inherits:
-
Object
- Object
- Groonga::Schema::IndexColumnDefinition
- Includes:
- Path
- Defined in:
- lib/groonga/schema.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target_columns ⇒ Object
Returns the value of attribute target_columns.
-
#target_table ⇒ Object
Returns the value of attribute target_table.
Class Method Summary collapse
Instance Method Summary collapse
- #define(table_definition, table) ⇒ Object
-
#initialize(name, options = {}) ⇒ IndexColumnDefinition
constructor
A new instance of IndexColumnDefinition.
Methods included from Path
#columns_directory_path, #rmdir_if_available, #tables_directory_path
Constructor Details
#initialize(name, options = {}) ⇒ IndexColumnDefinition
Returns a new instance of IndexColumnDefinition.
1897 1898 1899 1900 1901 1902 1903 |
# File 'lib/groonga/schema.rb', line 1897 def initialize(name, ={}) @name = name @name = @name.to_s if @name.is_a?(Symbol) @options = ( || {}).dup @target_table = nil @target_columns = nil end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
1894 1895 1896 |
# File 'lib/groonga/schema.rb', line 1894 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
1895 1896 1897 |
# File 'lib/groonga/schema.rb', line 1895 def @options end |
#target_columns ⇒ Object
Returns the value of attribute target_columns.
1894 1895 1896 |
# File 'lib/groonga/schema.rb', line 1894 def target_columns @target_columns end |
#target_table ⇒ Object
Returns the value of attribute target_table.
1894 1895 1896 |
# File 'lib/groonga/schema.rb', line 1894 def target_table @target_table end |
Class Method Details
.column_name(context, target_table, target_columns) ⇒ Object
1879 1880 1881 1882 |
# File 'lib/groonga/schema.rb', line 1879 def column_name(context, target_table, target_columns) target_table = resolve(context, target_table) "#{target_table.name}_#{target_columns.join('_')}" end |
.resolve(context, object) ⇒ Object
1884 1885 1886 1887 1888 1889 1890 1891 |
# File 'lib/groonga/schema.rb', line 1884 def resolve(context, object) return object if object.is_a?(Groonga::Object) if object.respond_to?(:call) object = object.call(context) end return nil if object.nil? context[object] end |
Instance Method Details
#define(table_definition, table) ⇒ Object
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 |
# File 'lib/groonga/schema.rb', line 1905 def define(table_definition, table) context = table_definition.context target_table = resolve_target_table(context) if target_table.nil? raise UnknownIndexTargetTable.new(@target_table) end nonexistent_columns = nonexistent_columns(target_table) unless nonexistent_columns.empty? raise UnknownIndexTarget.new(target_table, nonexistent_columns) end name = @name || self.class.column_name(context, target_table, @target_columns) index = table.column(name) if index return index if same_index?(context, index, target_table) if @options[:force] index.remove else = @options.merge(:type => :index, :target_table => target_table, :target_columns => @target_columns) raise ColumnCreationWithDifferentOptions.new(index, ) end end index = table.define_index_column(name, target_table, (context, table, name)) index.sources = @target_columns.collect do |column| target_table.column(column) end index end |