Class: Tarantool::Generators::ModelGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
tarantool-rails/lib/generators/tarantool/model/model_generator.rb

Overview

rails g tarantool:model User email:string age:unsigned?

Defined Under Namespace

Classes: Field

Constant Summary collapse

TYPES =
{
  'integer' => [':integer', 'integer'], 'unsigned' => [':integer', 'unsigned'], 'string' => [':string', 'string'],
  'boolean' => [':boolean', 'boolean'], 'decimal' => [':decimal', 'decimal'],
  'datetime' => [':datetime', 'datetime'], 'uuid' => ['Tarantool::Model::Types::UUID.new', 'uuid'],
  'interval' => ['Tarantool::Model::Types::Interval.new', 'interval'],
  'binary' => ['Tarantool::Model::Types::Binary.new', 'varbinary']
}.freeze
ID =
Field.new(name: 'id', attribute_type: ':integer', field_type: 'unsigned', nullable: false)
SCHEMA_PATH =
'config/tarantool_schema.rb'
SCHEMA_END =
/^end\s*\z/
LINE_START =
/^/

Instance Method Summary collapse

Instance Method Details

#add_space_to_schema ⇒ Object



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

def add_space_to_schema
  return if options[:skip_schema] || !File.exist?(File.join(destination_root, SCHEMA_PATH))

  inject_into_file SCHEMA_PATH, space_declaration, before: SCHEMA_END
end

#create_model_file ⇒ Object



38
39
40
# File 'tarantool-rails/lib/generators/tarantool/model/model_generator.rb', line 38

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

#parse_fields ⇒ Object

Runs before any file is written so an unknown type leaves nothing behind.



34
35
36
# File 'tarantool-rails/lib/generators/tarantool/model/model_generator.rb', line 34

def parse_fields
  model_fields
end