Sha256: 4a50b0c67b41bc909c798b36a7a16b077c962f18ea2ce612652453581adb9317

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Robotnik
  module Authorization
    class Law
      
      #--- Class methods ---#
      
          include Robotnik::DslEval
          
          cattr_reader :law
      
          def self.define &block
            @@law = self.new.evaluate(&block)
          end
          
          def self.reset!
            @@law = nil
          end
          
      #--- Instance methods ---#
      
          def status method, &block
            init_role_for(method).evaluate &block
          end
          
          def statuses
            rules.keys
          end
          
          def can? *args
            subject, args = args.shift, args
            verdict = false
            statuses.each do |status|
              if subject.send status
                verdict = rules[status].can? *args
                break
              end
            end
            verdict
          end
          
      private
      
          def rules
            @rules ||= {}.with_indifferent_access
          end
          
          def init_role_for method
            rules[method] ||= Robotnik::Authorization::Status.new
          end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stasi-0.0.1.alpha lib/stasi/authorization/law.rb