Sha256: 7b9cef5d6a466cba4aea244e1b3569089b84de7dd767d1f9d9b8829af2fc4166

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'sugar-high/class_ext'

module CanTango
  module PermissionEngine
    class Factory
      include ClassExt

      attr_accessor :ability

      # creates the factory for the ability
      # note that the ability contains the roles and role groups of the user (or account)
      # @param [Permits::Ability] the ability
      def initialize ability
        @ability = ability
      end

      def build!
        @evaluators ||= permission_types.inject([]) do |res, type|
          res << collector(type).build
          res
        end.flatten.compact
      end

      def collector(type)
        rules = store.send(:"#{type}_rules")
        CanTango::PermissionEngine::Collector.new(ability, rules, type)
      end

      def options
        ability.options
      end

      def store
        store_class.new :cantango_permissions, store_options
      end

      def store_class
        permissions_engine.store.default_class
      end

      def store_options
        permissions_engine.store.options.merge(:path => config_path)
      end

      def permission_types
        permissions_engine.types
      end

      def config_path
        permissions_engine.config_path
      end

      private

      def permissions_engine
        CanTango.config.permissions
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cantango-0.8.0 lib/cantango/permission_engine/factory.rb