Class: Apish::EndpointGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Apish::EndpointGenerator
- Defined in:
- lib/generators/apish/endpoint/endpoint_generator.rb
Instance Attribute Summary collapse
-
#action_name ⇒ Object
readonly
Returns the value of attribute action_name.
-
#controller_super_class_name ⇒ Object
readonly
Returns the value of attribute controller_super_class_name.
Class Method Summary collapse
Instance Method Summary collapse
- #install_controller ⇒ Object
- #install_controller_spec ⇒ Object
- #install_request_specs ⇒ Object
- #install_routing_spec ⇒ Object
- #install_view_specs ⇒ Object
- #install_views ⇒ Object
Instance Attribute Details
#action_name ⇒ Object (readonly)
Returns the value of attribute action_name.
7 8 9 |
# File 'lib/generators/apish/endpoint/endpoint_generator.rb', line 7 def action_name @action_name end |
#controller_super_class_name ⇒ Object (readonly)
Returns the value of attribute controller_super_class_name.
7 8 9 |
# File 'lib/generators/apish/endpoint/endpoint_generator.rb', line 7 def controller_super_class_name @controller_super_class_name end |
Class Method Details
.source_root ⇒ Object
18 19 20 21 |
# File 'lib/generators/apish/endpoint/endpoint_generator.rb', line 18 def self.source_root File.join File.dirname(__FILE__), 'templates' end |
Instance Method Details
#install_controller ⇒ Object
23 24 25 26 27 |
# File 'lib/generators/apish/endpoint/endpoint_generator.rb', line 23 def install_controller @controller_super_class_name = ask( 'What is the class name (without namespace) of the versioned super class for this API endpoints controller (press enter for ApiController)?' ) @controller_super_class_name = default_controller_super_class_name if @controller_super_class_name.blank? template "controller.erb", File.join( 'app', 'controllers', "#{controller_file_name}.rb" ) end |
#install_controller_spec ⇒ Object
29 30 31 |
# File 'lib/generators/apish/endpoint/endpoint_generator.rb', line 29 def install_controller_spec template "controller_spec.erb", File.join( 'spec', 'controllers', "#{controller_spec_file_name}.rb" ) end |
#install_request_specs ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/generators/apish/endpoint/endpoint_generator.rb', line 37 def install_request_specs return if action_names.blank? basename = ask( 'What base name would you like for the request_spec(s) (press enter for authenticated_request)?' ) basename = default_request_spec_base_name if basename.blank? action_names.each do |action_name| @action_name = action_name template "request_spec.erb", File.join( 'spec', 'requests', "#{request_spec_file_name( action_name, "#{basename}_spec" )}.rb" ) end end |
#install_routing_spec ⇒ Object
33 34 35 |
# File 'lib/generators/apish/endpoint/endpoint_generator.rb', line 33 def install_routing_spec template "routing_spec.erb", File.join( 'spec', 'routing', "#{routing_spec_file_name}.rb" ) end |
#install_view_specs ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/generators/apish/endpoint/endpoint_generator.rb', line 57 def install_view_specs return if action_names.blank? || [:view_specs] == false action_names.each do |action_name| template "view_spec.erb", File.join( 'spec', 'views', "#{view_spec_file_name( action_name )}.rb" ) end end |
#install_views ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/generators/apish/endpoint/endpoint_generator.rb', line 49 def install_views return if action_names.blank? action_names.each do |action_name| create_file File.join( 'app', 'views', view_file_name( action_name )) end end |