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.



23
24
25
26
27
28
# File 'lib/switch_user/data_source.rb', line 23

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.



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

def identifier
  @identifier
end

#loaderObject (readonly)

Returns the value of attribute loader.



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

def loader
  @loader
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#scopeObject (readonly)

Returns the value of attribute scope.



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

def scope
  @scope
end

Instance Method Details

#allObject



30
31
32
# File 'lib/switch_user/data_source.rb', line 30

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

#find_scope_id(scope_id) ⇒ Object



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

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