Class: Hanami::Commands::Generate::Action
- Defined in:
- lib/hanami/commands/generate/action.rb
Constant Summary collapse
- ACTION_SEPARATOR_MATCHER =
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.
/[\/,#]/
- CONTROLLER_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.
Utils::String::UNDERSCORE_SEPARATOR
- 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.
'#'.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.
/(\"|\'|\\)/
- UP_DIRECTORY =
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.
'..'.freeze
- DIRECTORY_TEST_NESTING_LEVELS =
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.
3
- 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.
'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.
{ '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
{ 'Show' => '/:id', 'Update' => '/:id', 'Destroy' => '/:id', 'New' => '/new', 'Edit' => '/:id/edit', }.freeze
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(options, application_name, controller_and_action_name) ⇒ Action
constructor
A new instance of Action.
- #map_templates ⇒ Object
- #post_process_templates ⇒ Object
- #template_options ⇒ Object private
Methods inherited from Abstract
Methods included from Generators::Generatable
#add_mapping, #argument_blank?, #generator, #process_templates, #start, #target_path, #template_source_path
Methods inherited from Command
Constructor Details
#initialize(options, application_name, controller_and_action_name) ⇒ Action
Returns a new instance of Action.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/hanami/commands/generate/action.rb', line 62 def initialize(, application_name, controller_and_action_name) super() 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_MATCHER) @application_name = Utils::String.new(application_name).classify @controller_directory = controller_name @controller_name = controller_name.join(CONTROLLER_SEPARATOR) @controller_class_name = Utils::String.new(@controller_name).classify @action_class_name = Utils::String.new(@action_name).classify @controller_url = @controller_name # FIXME Extract a new class: Utils::Url to handle conversion from paths or this naming assert_application_name! assert_controller_class_name! assert_action_name! assert_url! assert_http_method! end |
Instance Method Details
#destroy ⇒ Object
119 120 121 122 |
# File 'lib/hanami/commands/generate/action.rb', line 119 def destroy generator.gsub_file(routes_path, /^.*#{@controller_and_action_name}.*\n/, '', verbose: false) super end |
#map_templates ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/hanami/commands/generate/action.rb', line 89 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_templates ⇒ Object
102 103 104 |
# File 'lib/hanami/commands/generate/action.rb', line 102 def post_process_templates generate_route end |
#template_options ⇒ Object
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.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/hanami/commands/generate/action.rb', line 108 def { app: @application_name, controller: @controller_class_name, action: @action_class_name, relative_action_path: relative_action_path, relative_view_path: relative_view_path, template_path: template_path, } end |