Sha256: 38b5ab37a47f543f8fa3e69f083a8e8418fd4784ea483b1761ac616119761cc2

Contents?: true

Size: 789 Bytes

Versions: 26

Compression:

Stored size: 789 Bytes

Contents

module RoleAuthorization
  module Rules
    class Rule
      attr_accessor :role, :options
      attr_accessor :returning

      # for calls to authorized?
      attr_accessor :controller_instance, :controller, :action, :id

      def initialize(*options, &block)
        @returning = block
        @options, @role = if options.is_a?(Hash)
                            [options, nil]
                          elsif options.last.is_a?(Hash)
                            [options.pop, options.first]
                          else
                            [{}, options.first]
                          end

        self
      end

      def authorized?(*args)
        @controller_instance, @controller, @action, @id = args

        instance_eval(&returning)
      end
    end
  end
end



Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
role_authorization-0.5.0 lib/role_authorization/rules/rule.rb
role_authorization-0.4.5 lib/role_authorization/rules/rule.rb
role_authorization-0.4.4 lib/role_authorization/rules/rule.rb
role_authorization-0.4.3 lib/role_authorization/rules/rule.rb
role_authorization-0.4.2 lib/role_authorization/rules/rule.rb
role_authorization-0.4.1 lib/role_authorization/rules/rule.rb
role_authorization-0.4.0 lib/role_authorization/rules/rule.rb
role_authorization-0.3.9 lib/role_authorization/rules/rule.rb
role_authorization-0.3.8 lib/role_authorization/rules/rule.rb
role_authorization-0.3.7 lib/role_authorization/rules/rule.rb
role_authorization-0.3.6 lib/role_authorization/rules/rule.rb
role_authorization-0.3.5 lib/role_authorization/rules/rule.rb
role_authorization-0.3.4 lib/role_authorization/rules/rule.rb
role_authorization-0.3.3 lib/role_authorization/rules/rule.rb
role_authorization-0.3.2 lib/role_authorization/rules/rule.rb
role_authorization-0.3.1 lib/role_authorization/rules/rule.rb
role_authorization-0.3.0 lib/role_authorization/rules/rule.rb
role_authorization-0.2.8 lib/role_authorization/rules/rule.rb
role_authorization-0.2.7 lib/role_authorization/rules/rule.rb
role_authorization-0.2.6 lib/role_authorization/rules/rule.rb