Class: Lotus::Commands::Generate::Action

Inherits:
Abstract
  • Object
show all
Defined in:
lib/lotus/commands/generate/action.rb

Overview

Since:

  • 0.1.0

Constant Summary collapse

ACTION_SEPARATOR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

/[\/,#]/
ROUTE_ENDPOINT_SEPARATOR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

'#'.freeze
QUOTED_NAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

/(\"|\'|\\)/
DEFAULT_HTTP_METHOD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Default HTTP method used when generating an action.

Since:

  • 0.5.0

'GET'.freeze
RESOURCEFUL_HTTP_METHODS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

HTTP methods used when generating resourceful actions.

Since:

  • 0.6.0

{
  'Create'  => 'POST',
  'Update'  => 'PATCH',
  'Destroy' => 'DELETE'
}.freeze
RESOURCEFUL_ROUTE_URL_SUFFIXES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

For resourceful actions, what to add to the end of the base URL

Since:

  • 0.6.0

{
  'Show'    => '/:id',
  'Update'  => '/:id',
  'Destroy' => '/:id',
  'New'     => '/new',
  'Edit'    => '/:id/edit',
}.freeze

Instance Attribute Summary

Attributes inherited from Abstract

#options, #target_path

Instance Method Summary collapse

Methods inherited from Abstract

#template_source_path

Methods included from Generators::Generatable

#add_mapping, #destroy, #generator, #process_templates, #start, #target_path, #template_source_path

Constructor Details

#initialize(options, application_name, controller_and_action_name) ⇒ Action

Returns a new instance of Action.

Since:

  • 0.1.0



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lotus/commands/generate/action.rb', line 49

def initialize(options, application_name, controller_and_action_name)
  super(options)
  if !environment.container?
    application_name = File.basename(Dir.pwd)
  end

  controller_and_action_name = Utils::String.new(controller_and_action_name).underscore.gsub(QUOTED_NAME, '')

  *controller_name, action_name = controller_and_action_name.split(ACTION_SEPARATOR)

  @application_name = Utils::String.new(application_name).classify
  @controller_name = Utils::String.new(controller_name.join("/")).classify
  @action_name = Utils::String.new(action_name).classify
  @controller_pathname = Utils::String.new(@controller_name).underscore

  assert_application_name!
  assert_controller_name!
  assert_action_name!
  assert_http_method!
end

Instance Method Details

#map_templatesObject

Since:

  • 0.1.0



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/lotus/commands/generate/action.rb', line 70

def map_templates
  add_mapping("action_spec.#{test_framework.framework}.tt", action_spec_path)

  if skip_view?
    add_mapping('action_without_view.rb.tt', action_path)
  else
    add_mapping('action.rb.tt', action_path)
    add_mapping('view.rb.tt', view_path)
    add_mapping('template.tt', template_path)
    add_mapping("view_spec.#{test_framework.framework}.tt", view_spec_path)
  end
end

#post_process_templatesObject

Since:

  • 0.1.0



83
84
85
# File 'lib/lotus/commands/generate/action.rb', line 83

def post_process_templates
  generate_route
end

#template_optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



89
90
91
92
93
94
95
96
97
98
# File 'lib/lotus/commands/generate/action.rb', line 89

def template_options
  {
    app:                  @application_name,
    controller:           @controller_name,
    action:               @action_name,
    relative_action_path: relative_action_path,
    relative_view_path:   relative_view_path,
    template_path:        template_path,
  }
end