Sha256: 22dad5c955edc78bb45958f5f4efe729deb54dca944c20a3be23ff2f84c20130

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require 'rails/generators/base'
require 'sugar-high/array'
require 'active_support/inflector'
require 'rails3_artifactor'
require 'logging_assist'

module Cancan
  module Generators
    class LicensesGenerator < Rails::Generators::Base
      desc "Creates Licenses for use with CanCan and Permits"

      argument     :licenses,           :type => :array,      :default => [],     :desc => "Licenses"
      class_option :default_licenses,   :type => :boolean,    :default => true,   :desc => "Create default exemplar licenses"

      source_root File.dirname(__FILE__) + '/templates'

      def main_flow      
        if default_licenses?
          default_licenses.each{|license| default_license license }
        end  

        licenses.each do |license|      
          template_license(license) # if !skip_license?(license)
        end    
      end
  
      protected

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

      attr_accessor :license_name

      def skip_license? license
        default_licenses? && default_licenses.include?(license.to_sym) 
      end

      def default_licenses
        [:user_admin, :blogging]
      end        

      def default_licenses?
        options[:default_licenses]    
      end

      def template_license name  
        self.license_name = name        
        template "license.rb", "app/licenses/#{name}_license.rb"
      end
  
      def default_license name 
        template "#{name}_license.rb", "app/licenses/#{name}_license.rb"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cancan-permits-0.3.2 lib/generators/cancan/licenses/licenses_generator.rb