Class: ActiveGroonga::Generators::Column — activegroonga - Ranguba

Class: ActiveGroonga::Generators::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/generators/active_groonga/migration/column.rb

Overview

:nodoc:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Column) initialize(name, type, options)

Returns a new instance of Column



21
22
23
24
25
26
27
28
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 21

def initialize(name, type, options)
  if type.blank?
    message = "Missing type for attribute '#{name}'.\n" +
      "Example: '#{name}:short_text' where ShortText is the type."
    raise Thor::Error, message
  end
  @name, @type, @options = name, type.to_sym, options
end

Instance Attribute Details

- (Object) name

Returns the value of attribute name



19
20
21
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 19

def name
  @name
end

- (Object) options

Returns the value of attribute options



19
20
21
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 19

def options
  @options
end

- (Object) type

Returns the value of attribute type



19
20
21
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 19

def type
  @type
end

Instance Method Details

- (Object) create_code



30
31
32
33
34
35
36
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 30

def create_code
  if index?
    create_code_index
  else
    create_code_normal
  end
end

- (Boolean) index?

Returns:

  • (Boolean)


62
63
64
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 62

def index?
  @type == :index
end

- (Boolean) reference?

Returns:

  • (Boolean)


66
67
68
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 66

def reference?
  @type == :reference
end

- (Object) reference_table_name



70
71
72
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 70

def reference_table_name
  @name.pluralize
end

- (Object) remove_code



38
39
40
41
42
43
44
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 38

def remove_code
  if index?
    "remove_index(\"#{name}\")"
  else
    "remove_column(:#{name})"
  end
end

- (Boolean) vector?

Returns:

  • (Boolean)


46
47
48
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 46

def vector?
  @options.include?("vector")
end

- (Boolean) with_position?

Returns:

  • (Boolean)


58
59
60
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 58

def with_position?
  @options.include?("with_position")
end

- (Boolean) with_section?

Returns:

  • (Boolean)


50
51
52
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 50

def with_section?
  @options.include?("with_section")
end

- (Boolean) with_weight?

Returns:

  • (Boolean)


54
55
56
# File 'lib/rails/generators/active_groonga/migration/column.rb', line 54

def with_weight?
  @options.include?("with_weight")
end