Class: ActiveOutbox::Generators::ModelGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ActiveOutbox::Generators::ModelGenerator
show all
- Includes:
- AdapterHelper, Rails::Generators::Migration
- Defined in:
- lib/generators/active_outbox/model/model_generator.rb
Instance Method Summary
collapse
bigint_type, json_type, mysql?, postgres?, uuid_type
Instance Method Details
#aggregate_identifier_type ⇒ Object
#create_migration_file ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/generators/active_outbox/model/model_generator.rb', line 31
def create_migration_file
migration_path = "#{root_path}/db/migrate"
migration_template(
'migration.rb',
"#{migration_path}/active_outbox_create_#{table_name}.rb",
migration_version: migration_version
)
template('model.rb', "#{root_path}/app/models/#{path_name}.rb")
end
|
#migration_version ⇒ Object
47
48
49
|
# File 'lib/generators/active_outbox/model/model_generator.rb', line 47
def migration_version
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
end
|
#path_name ⇒ Object
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/generators/active_outbox/model/model_generator.rb', line 58
def path_name
name = ''
*namespace = model_name.downcase.split('/')
if (model_name.include?('/') && model_name.last != '/' && namespace.length > 1) || !model_name.include?('/')
name = namespace.pop
end
name = name.blank? ? 'outbox' : "#{name}_outbox"
namespace = namespace.join('/')
namespace.blank? ? name : "#{namespace}/#{name}"
end
|
#root_path ⇒ Object
42
43
44
45
|
# File 'lib/generators/active_outbox/model/model_generator.rb', line 42
def root_path
path = options['component_path'].blank? ? '' : "/#{options['component_path']}"
"#{Rails.root}#{path}"
end
|
#table_name ⇒ Object
51
52
53
54
55
56
|
# File 'lib/generators/active_outbox/model/model_generator.rb', line 51
def table_name
*namespace, name = model_name.downcase.split('/')
name = name.blank? ? 'outboxes' : "#{name}_outboxes"
namespace = namespace.join('_')
namespace.blank? ? name : "#{namespace}_#{name}"
end
|