Class: SwitchUser::DataSource
- Inherits:
-
Object
- Object
- SwitchUser::DataSource
- Defined in:
- lib/switch_user/data_source.rb
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #all ⇒ Object
- #find_scope_id(scope_id) ⇒ Object
-
#initialize(loader, scope, identifier, name) ⇒ DataSource
constructor
A new instance of DataSource.
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
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
19 20 21 |
# File 'lib/switch_user/data_source.rb', line 19 def identifier @identifier end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
19 20 21 |
# File 'lib/switch_user/data_source.rb', line 19 def loader @loader end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/switch_user/data_source.rb', line 19 def name @name end |
#scope ⇒ Object (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
#all ⇒ Object
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 |