Class: Drails::Generators::CommandGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Domain, EventName, ProcessorName
Defined in:
lib/generators/drails/command/command_generator.rb

Instance Method Summary collapse

Methods included from Domain

#domain_class_path

Methods included from EventName

#initialize

Methods included from ProcessorName

#initialize

Instance Method Details

#add_to_command_processorObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/drails/command/command_generator.rb', line 28

def add_to_command_processor
  return if skip_processor?
  content = "

    process #{class_name}Command do |command|
command.is_valid_do { event #{event_class_name}Event.new command.to_hash }
    end"
  file = File.join('domain/command_processors', processor_domain_class_path, "#{processor_file_name}_processor.rb")
  inject_into_file file, content, after: /(\s)*include(\s)*ActiveDomain::CommandProcessor/
end

#create_command_fileObject



14
15
16
# File 'lib/generators/drails/command/command_generator.rb', line 14

def create_command_file
  template 'command.rb', File.join('app/commands', class_path, "#{file_name}_command.rb")
end

#create_command_processorObject



23
24
25
26
# File 'lib/generators/drails/command/command_generator.rb', line 23

def create_command_processor
  return if skip_processor?
  generate 'drails:command_processor', processor_file_path, '-s', '--skip-namespace'
end


18
19
20
21
# File 'lib/generators/drails/command/command_generator.rb', line 18

def create_related_event_file
  return if skip_event?
  template 'event.rb', File.join('app/events', event_class_path, "#{event_file_name}_event.rb")
end