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.
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
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
21 22 23 |
# File 'lib/switch_user/data_source.rb', line 21 def identifier @identifier end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
21 22 23 |
# File 'lib/switch_user/data_source.rb', line 21 def loader @loader end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/switch_user/data_source.rb', line 21 def name @name end |
#scope ⇒ Object (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
#all ⇒ Object
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 |