Sha256: 978fa6cb9d1eaf0614e4fe7a2976734eac890192aee875d9593ee8faa39e533c

Contents?: true

Size: 1018 Bytes

Versions: 8

Compression:

Stored size: 1018 Bytes

Contents

require 'generators/cantango/basic'

module Cantango
  module Generators
    class Base < ::Rails::Generators::Base

      include Cantango::Generators::Basic

      CAN_ACTIONS = [:create, :update, :manage, :read, :access]

      CAN_ACTIONS.each do |action|
        class_eval %{
          class_option :#{action},      :type => :array,     :default => [],  :desc => "Models allowed to #{action}"
        }
      end

      protected

      [:user, :account].each do |name|
        define_method :"#{name}?" do
          false
        end
      end

      CAN_ACTIONS.each do |action|
        class_eval %{
          def #{action}
            options[:#{action}]
          end
        }
      end

      def rules_logic
        CAN_ACTIONS.map do |action|
          send(action).map do |c|
            "can(:#{action}, #{act_model(c)})"
          end.join("\n    ")
        end.join("\n")
      end

      def act_model name
        return ':all' if name == 'all'
        name.camelize
      end
    end
  end
end


Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cantango-0.8.9 lib/generators/cantango/base.rb
cantango-0.8.8.1 lib/generators/cantango/base.rb
cantango-0.8.8 lib/generators/cantango/base.rb
cantango-0.8.7 lib/generators/cantango/base.rb
cantango-0.8.6.2 lib/generators/cantango/base.rb
cantango-0.8.6.1 lib/generators/cantango/base.rb
cantango-0.8.6 lib/generators/cantango/base.rb
cantango-0.8.5.1 lib/generators/cantango/base.rb