module Stager class ScaffoldGenerator < Rails::Generators::Base no_tasks { attr_accessor :scaffold_name, :model_attributes } source_root File.expand_path('../templates', __FILE__) argument :scaffold_name, :type => :string, :required => true argument :model_and_controller_args, :type => :array, :default => [] class_option :namespaced_model, :type => :boolean, :default => false class_option :skip_migration, :type => :boolean, :default => false class_option :skip_timestamps, :type => :boolean, :default => false class_option :skip_presenter, :type => :boolean, :default => false class_option :skip_views, :type => :boolean, :default => false class_option :skip_helper, :type => :boolean, :default => false def set_options @model_attributes = [] @invert_actions = false @skip_model = false model_and_controller_args.each do |arg| if arg.include?(':') @model_attributes << arg end end if @model_attributes.empty? @skip_model = true end end def create_model unless @skip_model invoke "stager:model", [namespaced_scaffold_name?, model_attributes, option?(:skip_migration), option?(:skip_timestamps)] end end def create_controller invoke "stager:controller", [scaffold_name.pluralize, model_and_controller_args, option?(:namespaced_model), option?(:skip_views), option?(:skip_helper)] end def create_presenter unless options[:skip_presenter] invoke "exhibit:presenter", [scaffold_name, options[:namespaced_model] ? nil : "--no_namespace"] end end private def namespaced_scaffold_name? if options[:namespaced_model] scaffold_name else scaffold_name.underscore.split("/").last end end def option?(value) options[value] ? "--#{value}" : nil end end end