Class: Reativo::OpGenerator

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

Constant Summary collapse

MAP =
{
  index:   { operation: true, contract: false, representer: true},
  create:  { operation: true, contract: true,  representer: true},
  show:    { operation: true, contract: false, representer: false},
  update:  { operation: true, contract: true,  representer: true},
  destroy: { operation: true, contract: false, representer: false},
}

Instance Method Summary collapse

Instance Method Details

#generate_operationsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/generators/reativo/op_generator.rb', line 45

def generate_operations
  representer_module = false
  actions = options['actions'] || []

  actions = ['index', 'create', 'show', 'update', 'destroy'] if options[:crud]

  actions.each do |action|
    template "operation/#{action}.erb", concept_path("operation", action) if has_operation?(action)
    template "contract/#{action}.erb", concept_path("contract", action) if has_contract?(action)
    if has_representer?(action)
      template "representer/#{action}.erb", concept_path("representer", action)
      representer_module = true
    end
  end

  if representer_module
    template "representer/module.erb", concept_path("representer", "#{representer_path(model_name)}_module")
  end
end