Sha256: 1a4a2d1afb8145474cc1eef687d3f50967a08237deaaa9d47e0503c9b6e2f847

Contents?: true

Size: 1.79 KB

Versions: 37

Compression:

Stored size: 1.79 KB

Contents

module MobileWorkflow
  module Generators
    # Custom scaffolding generator
    # https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb
    class ControllerGenerator < Rails::Generators::NamedBase
      include Rails::Generators::ResourceHelpers
      source_root File.expand_path("../templates", __FILE__)
      
      class_option :attributes, type: :array, default: [], banner: "field:type field:type"
      class_option :actions, type: :array, default: [], banner: "index create update destroy"
      class_option :doorkeeper_oauth, type: :boolean, default: false
      class_option :s3_storage, type: :boolean, default: false
      
      def copy_controller_and_spec_files
        template "controller.rb.erb", File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
        template "controller_spec.rb.erb", File.join("spec/controllers", controller_class_path, "#{controller_file_name}_controller_spec.rb")
      end
      
      private
      def doorkeeper_oauth?
        options[:doorkeeper_oauth]
      end
      
      def s3_storage?
        options[:s3_storage]
      end
      
      def attributes_names
        options[:attributes].map{ |attribute| attribute.split(":").first }
      end
          
      def permitted_params
        permitted_attributes = attributes_names.dup
        permitted_attributes.delete('user')
        permitted_attributes.map{ |name| ":#{name}" }.join(", ")
      end
      
      def index_action?
        actions.include?("index")
      end
      
      def show_action?
        actions.include?("show")
      end
      
      def create_action?
        actions.include?("create")
      end
      
      def actions
        options[:actions]
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
mobile_workflow-0.6.26 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.25 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.24 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.23 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.22 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.21 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.20 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.19 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.18 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.17 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.16 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.15 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.14 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.13 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.12 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.11 lib/generators/mobile_workflow/controller_generator.rb
mobile_workflow-0.6.10 lib/generators/mobile_workflow/controller_generator.rb