Class: ActiveGroonga::Generators::ModelGenerator — activegroonga - ラングバ

Class: ActiveGroonga::Generators::ModelGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/rails/generators/active_groonga/model/model_generator.rb

Instance Method Summary (collapse)

Methods inherited from Base

base_root, next_migration_number

Constructor Details

- (ModelGenerator) initialize(args, *options)

Returns a new instance of ModelGenerator



33
34
35
36
37
38
39
40
# File 'lib/rails/generators/active_groonga/model/model_generator.rb', line 33

def initialize(args, *options)
  super
  @key = nil
  @table_type = nil
  @key_normalize = false
  @default_tokenizer = nil
  parse_columns!
end

Instance Method Details

- (Object) create_migration_file



42
43
44
45
46
# File 'lib/rails/generators/active_groonga/model/model_generator.rb', line 42

def create_migration_file
  return unless options[:migration] && options[:parent].nil?
  migration_template("migration.rb",
                     "db/groonga/migrate/create_#{table_name}.rb")
end

- (Object) create_model_file



48
49
50
51
# File 'lib/rails/generators/active_groonga/model/model_generator.rb', line 48

def create_model_file
  template('model.rb',
           File.join("app/models", class_path, "#{file_name}.rb"))
end

- (Object) create_module_file



53
54
55
56
57
58
# File 'lib/rails/generators/active_groonga/model/model_generator.rb', line 53

def create_module_file
  return if class_path.empty?
  if behavior == :invoke
    template('module.rb', "app/models/#{class_path.join('/')}.rb")
  end
end

- (Object) create_table_code



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rails/generators/active_groonga/model/model_generator.rb', line 60

def create_table_code
  code = "create_table(:#{table_name}"
  options = []
  options << ":type => :#{@table_type}" if @table_type
  options << ":key_type => \"#{@key}\"" if @key
  options << ":key_normalize => #{@key_normalize}" if @key_normalize
  options << ":default_tokenizer => \"#{@tokenizer}\"" if @tokenizer
  code << ", #{options.join(', ')}" unless options.empty?
  code << ")"
  code
end

- (Object) remove_table_code



72
73
74
# File 'lib/rails/generators/active_groonga/model/model_generator.rb', line 72

def remove_table_code
  "remove_table(:#{table_name})"
end