class Reativo::OpGenerator

Constants

MAP

Public Instance Methods

generate_operations() click to toggle source
# 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

Private Instance Methods

concept_path(operation, action) click to toggle source
# File lib/generators/reativo/op_generator.rb, line 76
def concept_path(operation, action)
  "app/concepts/#{class_name.underscore}/#{operation}/#{action}.rb"
end
has_contract?(action) click to toggle source
# File lib/generators/reativo/op_generator.rb, line 84
def has_contract?(action)
  MAP.dig(action.to_sym, :contract) || false
end
has_operation?(action) click to toggle source
# File lib/generators/reativo/op_generator.rb, line 80
def has_operation?(action)
  MAP.dig(action.to_sym, :operation) || false
end
has_representer?(action) click to toggle source
# File lib/generators/reativo/op_generator.rb, line 88
def has_representer?(action)
  MAP.dig(action.to_sym, :representer) || false
end
properties_symbols(include_id:) click to toggle source
# File lib/generators/reativo/op_generator.rb, line 70
def properties_symbols(include_id:)
  args = options[:properties].dup
  args.prepend(:id) if include_id
  args.map { |x| ":#{x}" }.join(", ")
end
property_attribute(property) click to toggle source
# File lib/generators/reativo/op_generator.rb, line 66
def property_attribute(property)
  return "property :#{property}"
end
representer_path(model_name) click to toggle source
# File lib/generators/reativo/op_generator.rb, line 92
def representer_path(model_name)
  model_name.demodulize.underscore
end