Class: DryModuleGenerator::Generator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/dry_module_generator/module/generator.rb

Constant Summary collapse

TYPE_TO_DRY_TYPE =
{
  'array': "Types::Array",
  'boolean': "Types::Bool",
  'date': "Types::Date",
  'datetime': "Types::DateTime",
  'float': "Types::Float",
  'integer': "Types::Integer",
  'string': "Types::String",
  'time': "Types::Time"
}.freeze
TYPE_TO_FORM_FIELD =
{
  'string': "text_field_tag",
  'date': "date_field_tag",
  'time': "time_field_tag",
  'datetime': "datetime_field_tag",
  'integer': "number_field_tag",
  'float': "text_field_tag",
  'boolean': "check_box_tag"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(args, *options) ⇒ Generator

Returns a new instance of Generator.



33
34
35
36
# File 'lib/dry_module_generator/module/generator.rb', line 33

def initialize(args, *options)
  super
  self.module_name = args[0]
end

Instance Method Details

#create_appObject



38
39
40
41
42
# File 'lib/dry_module_generator/module/generator.rb', line 38

def create_app
  template("app/service.rb", File.join("#{module_path}/app/#{class_name.downcase}_service.rb"))
  template("app/list_dto.rb", File.join("#{module_path}/app/get_#{class_name.pluralize.downcase}_list_dto.rb"))
  template("app/details_dto.rb", File.join("#{module_path}/app/get_#{class_name.downcase}_details_dto.rb"))
end

#create_domainObject



44
45
46
# File 'lib/dry_module_generator/module/generator.rb', line 44

def create_domain
  template("domain/model.rb", File.join("#{module_path}/domain/#{class_name.downcase}.rb"))
end

#create_infraObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dry_module_generator/module/generator.rb', line 48

def create_infra
  template("infra/system/provider_source.rb", File.join("#{module_path}/infra/system/provider_source.rb"))
  @timestamp = Time.now.strftime("%Y%m%d%H%M%S")
  template(
    "infra/db/migrate/migration.rb",
    File.join(
      "#{module_path}/infra/db/migrate/#{@timestamp}_create_#{class_name.downcase.pluralize}.rb"
    )
  )
  template("infra/config/application.rb", File.join("#{module_path}/infra/config/application.rb"))
  template("infra/config/routes.rb", File.join("#{module_path}/infra/config/routes.rb"))
end

#create_uiObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dry_module_generator/module/generator.rb', line 61

def create_ui
  @action_type = "Create"
  template("ui/create_validation.rb", File.join("#{module_path}/ui/create_#{class_name.downcase}_validator.rb"))
  template("spec/ui/validation_test.rb",
           File.join("#{module_name}/spec/ui/create_#{class_name.downcase}_validator_spec.rb"))
  @action_type = "Update"
  template("ui/update_validation.rb", File.join("#{module_path}/ui/update_#{class_name.downcase}_validator.rb"))
  template("spec/ui/validation_test.rb",
           File.join("#{module_name}/spec/ui/update_#{class_name.downcase}_validator_spec.rb"))

  template("ui/controller.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}_controller.rb"))
end

#create_viewsObject



74
75
76
77
78
79
80
# File 'lib/dry_module_generator/module/generator.rb', line 74

def create_views
  template("ui/views/form.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}/_form.html.erb"))
  template("ui/views/index.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}/index.html.erb"))
  template("ui/views/show.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}/show.html.erb"))
  template("ui/views/new.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}/new.html.erb"))
  template("ui/views/edit.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}/edit.html.erb"))
end