Class: Xcflushd::Authorization

Inherits:
Struct
  • Object
show all
Defined in:
lib/xcflushd/authorization.rb,
lib/xcflushd/authorization.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authorized, reason = nil) ⇒ Authorization

Returns a new instance of Authorization.



3
4
5
# File 'lib/xcflushd/authorization.rb', line 3

def initialize(authorized, reason = nil)
  super(authorized, authorized ? nil : reason)
end

Instance Attribute Details

#allowedObject

Returns the value of attribute allowed

Returns:

  • (Object)

    the current value of allowed



2
3
4
# File 'lib/xcflushd/authorization.rb', line 2

def allowed
  @allowed
end

#reasonObject

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



2
3
4
# File 'lib/xcflushd/authorization.rb', line 2

def reason
  @reason
end

Class Method Details

.allowObject



30
31
32
# File 'lib/xcflushd/authorization.rb', line 30

def self.allow
  ALLOWED
end

.deny(reason = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/xcflushd/authorization.rb', line 38

def self.deny(reason = nil)
  if reason.nil?
    DENIED
  # this test has to be done in case the code changes
  elsif reason == LIMITS_EXCEEDED_CODE
    LIMITS_EXCEEDED
  else
    new(false, reason)
  end
end

.deny_over_limitsObject



34
35
36
# File 'lib/xcflushd/authorization.rb', line 34

def self.deny_over_limits
  LIMITS_EXCEEDED
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/xcflushd/authorization.rb', line 7

def authorized?
  allowed
end

#limits_exceeded?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/xcflushd/authorization.rb', line 26

def limits_exceeded?
  reason == LIMITS_EXCEEDED_CODE
end