Class: SwitchUser::DataSource

Inherits:
Object
  • Object
show all
Defined in:
lib/switch_user/data_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loader, scope, identifier, name) ⇒ DataSource

Returns a new instance of DataSource.



21
22
23
24
25
26
# File 'lib/switch_user/data_source.rb', line 21

def initialize(loader, scope, identifier, name)
  @loader = loader
  @scope = scope
  @identifier = identifier
  @name = name
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



19
20
21
# File 'lib/switch_user/data_source.rb', line 19

def identifier
  @identifier
end

#loaderObject (readonly)

Returns the value of attribute loader.



19
20
21
# File 'lib/switch_user/data_source.rb', line 19

def loader
  @loader
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/switch_user/data_source.rb', line 19

def name
  @name
end

#scopeObject (readonly)

Returns the value of attribute scope.



19
20
21
# File 'lib/switch_user/data_source.rb', line 19

def scope
  @scope
end

Instance Method Details

#allObject



28
29
30
# File 'lib/switch_user/data_source.rb', line 28

def all
  loader.call.map { |user| Record.new(user, self) }
end

#find_scope_id(scope_id) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/switch_user/data_source.rb', line 32

def find_scope_id(scope_id)
  scope_regexp = /\A#{scope}_/
  return unless scope_id =~ scope_regexp

  user = loader.call.where(identifier => scope_id.sub(scope_regexp, '')).first
  Record.new(user, self)
end