Class: Robotnik::Authorization::Law
- Inherits:
-
Object
- Object
- Robotnik::Authorization::Law
- Includes:
- DslEval
- Defined in:
- lib/stasi/authorization/law.rb
Instance Attribute Summary collapse
-
#statuses ⇒ Object
readonly
— Instance methods —#.
Class Method Summary collapse
Instance Method Summary collapse
- #can?(action, resource, options) ⇒ Boolean
- #default(&block) ⇒ Object
-
#initialize ⇒ Law
constructor
A new instance of Law.
- #status(method, &block) ⇒ Object
Constructor Details
#initialize ⇒ Law
Returns a new instance of Law.
25 26 27 |
# File 'lib/stasi/authorization/law.rb', line 25 def initialize @statuses = [] end |
Instance Attribute Details
#statuses ⇒ Object (readonly)
— Instance methods —#
23 24 25 |
# File 'lib/stasi/authorization/law.rb', line 23 def statuses @statuses end |
Class Method Details
.define(&block) ⇒ Object
9 10 11 |
# File 'lib/stasi/authorization/law.rb', line 9 def self.define &block @@law = self.new.evaluate(&block) end |
.law ⇒ Object
17 18 19 |
# File 'lib/stasi/authorization/law.rb', line 17 def self.law @@law end |
.reset! ⇒ Object
13 14 15 |
# File 'lib/stasi/authorization/law.rb', line 13 def self.reset! @@law = nil end |
Instance Method Details
#can?(action, resource, options) ⇒ Boolean
37 38 39 40 41 42 43 44 45 |
# File 'lib/stasi/authorization/law.rb', line 37 def can? action, resource, verdict = false statuses.each do |status| if status == :default || status.to_proc.call([:agent]) verdict = rules[status].can? action.to_sym, resource, end end verdict end |
#default(&block) ⇒ Object
33 34 35 |
# File 'lib/stasi/authorization/law.rb', line 33 def default &block status :default, &block end |
#status(method, &block) ⇒ Object
29 30 31 |
# File 'lib/stasi/authorization/law.rb', line 29 def status method, &block init_role_for(method).evaluate &block end |