Class: SqAuth::SqAuthSession

Inherits:
Object
  • Object
show all
Defined in:
lib/sq_auth/sq_auth_session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ SqAuthSession

Returns a new instance of SqAuthSession.



4
5
6
7
# File 'lib/sq_auth/sq_auth_session.rb', line 4

def initialize value
  @cache = SqAuthCache.new
  @session_value = value
end

Instance Attribute Details

#session_valueObject (readonly)

Returns the value of attribute session_value.



3
4
5
# File 'lib/sq_auth/sq_auth_session.rb', line 3

def session_value
  @session_value
end

Instance Method Details

#project_roles(project) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sq_auth/sq_auth_session.rb', line 18

def project_roles project
  result = @cache.fetch(project)
  if result.nil?
    fetched_roles = yield(self, project)
    if fetched_roles
      @cache.save(project, fetched_roles)
    else
      return []
    end
  else
    result
  end
end

#role_exist?(roles, project, &block) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
# File 'lib/sq_auth/sq_auth_session.rb', line 9

def role_exist? roles, project, &block
  result = @cache.fetch(project)
  if result.nil?
	yield(self, roles, project)
  else
    !([*roles] & result).empty?
  end
end