Class: Stager::ControllerGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Stager::ControllerGenerator
- Defined in:
- lib/generators/stager/controller/controller_generator.rb
Instance Method Summary collapse
Instance Method Details
#create_controller ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/generators/stager/controller/controller_generator.rb', line 50 def create_controller template 'controller.rb', "app/controllers/#{plural_name}_controller.rb" template 'helper.rb', "app/helpers/#{plural_name}_helper.rb" unless [:skip_helper] namespaces = plural_name.split('/') resource = namespaces.pop if namespaces.present? route "namespace(:#{namespaces.first}) { resources :#{resource} }" else route "resources :#{resource}" end template "spec/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb" end |
#create_views ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/generators/stager/controller/controller_generator.rb', line 65 def create_views unless [:skip_views] controller_actions.each do |action| if %w[index show new edit].include?(action) template "views/#{action}.html.haml", "app/views/#{plural_name}/#{action}.html.haml" end end if form_partial? template "views/_form.html.haml", "app/views/#{plural_name}/_form.html.haml" end end end |
#set_options ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/generators/stager/controller/controller_generator.rb', line 15 def @controller_actions = [] @model_attributes = [] @invert_actions = false @namespaced_model = false model_and_controller_args.each do |arg| if arg == '!' @invert_actions = true elsif arg.include?(':') @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':')) else @controller_actions << arg @controller_actions << 'create' if arg == 'new' @controller_actions << 'update' if arg == 'edit' end end if [:namespaced_model] @namespaced_model = true end if @invert_actions || @controller_actions.empty? @controller_actions = all_actions - @controller_actions end if @model_attributes.empty? if model_exists? model_columns_for_attributes.each do |column| @model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s) end end end end |