Sha256: bcd86c108610c554baba79e180ae72660fa9c3a7de479bb5562934628b0267f3

Contents?: true

Size: 1.79 KB

Versions: 6

Compression:

Stored size: 1.79 KB

Contents

require 'sugar-high/file'
require 'sugar-high/module'
require 'cream'
require 'rails3_artifactor'
require 'logging_assist'

module Permits
  module Generators 
    class ConfigGenerator < Rails::Generators::Base        
      desc "Configure Permits"

      # ORM to use
      class_option :orm,      :type => :string,   :default => 'active_record',    :desc => "ORM to use"
      class_option :roles,    :type => :array,    :default => ['guest', 'admin'], :desc => "Roles for permits"
      class_option :logfile,  :type => :string,   :default => nil,                :desc => "Logfile location" 
      class_option :gems,     :type => :boolean,  :default => false,              :desc => "Add gems to gemfile?"       

      def configure_permits
      	logger.add_logfile :logfile => logfile if logfile
        logger.debug "Configure Permits"

		    permits_gems if gems?

        # Run permits generator to generate permit for each role
        rgen "cancan:permits --roles #{roles} --orm #{orm}"
        rgen "cancan:licenses"
      end           

      protected        
      
      include Rails3::Assist::BasicLogger
      extend Rails3::Assist::UseMacro
      
      use_helpers :app, :file, :special

      def gems?
        options[:gems]        
      end

      # rails generate ...
      def rgen command
        execute "rails g #{command}"
      end        

      def execute command
        logger.debug command
        run command
      end        

      def logfile
        options[:logfile]
      end

      def roles
        options[:roles]
      end

      def orm
        options[:orm]
      end

      def permits_gems
        gem 'cancan-permits'
        bundle_install # 'cancan-permits'
      end

      def bundle_install #*gems
        run "bundle install" # #{gems.jon(' ')}"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cream-0.8.2 lib/generators/permits/config/config_generator.rb
cream-0.8.1 lib/generators/permits/config/config_generator.rb
cream-0.8.0 lib/generators/permits/config/config_generator.rb
cream-0.7.10 lib/generators/permits/config/config_generator.rb
cream-0.7.8 lib/generators/permits/config/config_generator.rb
cream-0.7.7 lib/generators/permits/config/config_generator.rb