Class: InteractorGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ccios/interactor_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(parser, config) ⇒ InteractorGenerator

Returns a new instance of InteractorGenerator.



6
7
8
9
# File 'lib/ccios/interactor_generator.rb', line 6

def initialize(parser, config)
  @parser = parser
  @config = config
end

Instance Method Details

#generate(interactor_name, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ccios/interactor_generator.rb', line 11

def generate(interactor_name, options = {})
  interactor_group = @parser.interactor_group
  interactor_name = interactor_name.gsub("Interactor", "")
  new_group_name = "#{interactor_name}Interactor"

  associate_path_to_group = !interactor_group.path.nil?

  raise "[Error] Group #{new_group_name} already exists in #{app_group.display_name}" if interactor_group[new_group_name]
  new_group_path = File.join(interactor_group.real_path, new_group_name)
  new_group = interactor_group.pf_new_group(
    associate_path_to_group: associate_path_to_group,
    name: new_group_name,
    path: new_group_path
  )

  file_creator = FileCreator.new(options)
  target = @parser.core_target
  file_creator.create_file(interactor_name, 'Interactor', new_group, target)
  file_creator.create_file(interactor_name, 'InteractorImplementation', new_group, target)

  file_creator.print_file_content(interactor_name, 'InteractorAssembly')
end