Class: Hipaapotamus::Policy

Inherits:
Object
  • Object
show all
Defined in:
lib/hipaapotamus/policy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent, protected) ⇒ Policy

Returns a new instance of Policy.



7
8
9
# File 'lib/hipaapotamus/policy.rb', line 7

def initialize(agent, protected)
  @agent, @protected = agent, protected
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



5
6
7
# File 'lib/hipaapotamus/policy.rb', line 5

def agent
  @agent
end

#protectedObject (readonly)

Returns the value of attribute protected.



5
6
7
# File 'lib/hipaapotamus/policy.rb', line 5

def protected
  @protected
end

Class Method Details

.authorize!(agent, protected, action) ⇒ Object



36
37
38
# File 'lib/hipaapotamus/policy.rb', line 36

def authorize!(agent, protected, action)
  new(agent, protected).authorize!(action)
end

Instance Method Details

#access?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/hipaapotamus/policy.rb', line 23

def access?
  false
end

#authorize!(action) ⇒ Object



15
16
17
# File 'lib/hipaapotamus/policy.rb', line 15

def authorize!(action)
  authorized?(action) || raise(AccountabilityError, "#{agent.hipaapotamus_display_name} does not have #{action} privileges to #{protected.hipaapotamus_display_name}")
end

#authorized?(action) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/hipaapotamus/policy.rb', line 11

def authorized?(action)
  SystemAgent === agent || try(:"#{action}?")
end

#creation?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/hipaapotamus/policy.rb', line 19

def creation?
  false
end

#destruction?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/hipaapotamus/policy.rb', line 31

def destruction?
  false
end

#modification?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/hipaapotamus/policy.rb', line 27

def modification?
  false
end