Sha256: a16bf2f74f1dd02cb59a8736f962ad84c589ea39738748509afcab24d10e7daa

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module CanTango
  module PermitEngine
    class Finder
      include ClassExt

      # This class is used to find the right permit, possible scoped for a specific user account

      attr_reader :user_account, :name

      def initialize user_account, name
        @user_account = user_account
        @name = name
      end

      def get_permit
        begin
          find_first_class account_permit_class, permit_class
        rescue
          raise "Permit for #{type} #{name} could not be loaded. Define either class: #{account_permit_class} or #{permit_class}"
        end
      end

      # this is used to namespace role permits for a specific type of user account
      # this allows role permits to be defined differently for each user account (and hence sub application) if need be
      # otherwise it will fall back to the generic role permit (the one which is not wrapped in a user account namespace)
      def account_permit_class
        [account_permit_ns , permit_class].join('::')
      end

      def account_permit_ns
        "#{user_account.class}Permits"
      end

      def permit_class
        "#{name.to_s.camelize}Permit"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cantango-0.8.0 lib/cantango/permit_engine/finder.rb