Class: Formed::Generators::FormGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/active_form/form_generator.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#class_nameObject



38
39
40
41
42
43
44
# File 'lib/generators/active_form/form_generator.rb', line 38

def class_name
  name = super
  unless name.end_with?("Form")
    name += "Form"
  end
  name
end

#create_model_fileObject



12
13
14
15
16
# File 'lib/generators/active_form/form_generator.rb', line 12

def create_model_file
  generate_abstract_class if !custom_parent?

  template "form.rb", File.join("app/forms", class_path, "#{file_name}.rb")
end

#create_module_fileObject



18
19
20
21
22
# File 'lib/generators/active_form/form_generator.rb', line 18

def create_module_file
  return if regular_class_path.empty?

  template "module.rb", File.join("app/forms", "#{class_path.join('/')}.rb") if behavior == :invoke
end

#create_rspec_fileObject



24
25
26
27
28
# File 'lib/generators/active_form/form_generator.rb', line 24

def create_rspec_file
  return unless Rails.application.config.generators.test_framework == :rspec

  template 'form_spec.rb',  File.join("spec/forms", class_path, "#{file_name}_spec.rb")
end

#file_nameObject



30
31
32
33
34
35
36
# File 'lib/generators/active_form/form_generator.rb', line 30

def file_name
  name = super
  unless name.end_with?("_form")
    name += "_form"
  end
  name
end