Class: LightService::Generators::ActionGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
GeneratorUtils
Defined in:
lib/generators/light_service/action_generator.rb

Instance Method Summary collapse

Methods included from GeneratorUtils

#create_required_gen_vals_from, #make_nested_dir, #must_gen_tests?, #supported_test_frameworks, #test_framework, #test_framework_supported?

Instance Method Details

#create_actionObject

rubocop:disable Metrics/MethodLength,Metrics/AbcSize



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/generators/light_service/action_generator.rb', line 59

def create_action
  gen_vals = create_required_gen_vals_from(name)

  @module_path     = gen_vals[:module_path]
  @class_name      = gen_vals[:class_name]
  @full_class_name = gen_vals[:full_class_name]
  @expects         = keys["expects"].to_s.downcase.split(',')
  @promises        = keys["promises"].to_s.downcase.split(',')

  file_name = gen_vals[:file_name]
  file_path = gen_vals[:file_path]

  root_dir    = options.dir.downcase
  action_dir  = File.join('app', root_dir, *file_path)
  action_file = "#{action_dir}/#{file_name}"

  make_nested_dir(action_dir)
  template("action_template.erb", action_file)

  return unless must_gen_tests?

  spec_dir       = File.join('spec', root_dir, *file_path)
  spec_file_name = gen_vals[:spec_file_name]
  spec_file      = "#{spec_dir}/#{spec_file_name}"

  make_nested_dir(spec_dir)
  template("action_spec_template.erb", spec_file)
end