Class: Apish::EndpointGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/apish/endpoint/endpoint_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#action_nameObject (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_nameObject (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_rootObject



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_controllerObject



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_specObject



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_specsObject



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_specObject



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_specsObject



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? || options[: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_viewsObject



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