Class: Machina::Middleware::Authentication::Hints

Inherits:
Data
  • Object
show all
Defined in:
lib/machina/middleware/authentication/hints.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#organizationObject (readonly)

Returns the value of attribute organization

Returns:

  • (Object)

    the current value of organization



26
27
28
# File 'lib/machina/middleware/authentication/hints.rb', line 26

def organization
  @organization
end

#workspaceObject (readonly)

Returns the value of attribute workspace

Returns:

  • (Object)

    the current value of workspace



26
27
28
# File 'lib/machina/middleware/authentication/hints.rb', line 26

def workspace
  @workspace
end

Class Method Details

.from(env, request) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/machina/middleware/authentication/hints.rb', line 27

def self.from(env, request)
  new(
    workspace: env['machina.workspace_hint'].presence ||
      request.headers['X-Machina-Workspace-Hint'].presence,
    organization: env['machina.organization_hint'].presence ||
      request.headers['X-Machina-Organization-Hint'].presence,
  )
end

Instance Method Details

#cache_suffixObject



47
48
49
# File 'lib/machina/middleware/authentication/hints.rb', line 47

def cache_suffix
  empty? ? '' : ":#{organization}:#{workspace}"
end

#empty?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/machina/middleware/authentication/hints.rb', line 36

def empty?
  workspace.nil? && organization.nil?
end

#to_resolve_kwargsObject



40
41
42
43
44
45
# File 'lib/machina/middleware/authentication/hints.rb', line 40

def to_resolve_kwargs
  kwargs = {}
  kwargs[HINT_UUID_RE.match?(workspace) ? :workspace_id : :workspace_slug] = workspace if workspace
  kwargs[:organization_slug] = organization if organization
  kwargs
end