Class: SwitchUser::UserSet

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

Defined Under Namespace

Classes: Record

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, identifier, label, base_scope) ⇒ UserSet

Returns a new instance of UserSet.



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

def initialize(scope, identifier, label, base_scope)
  @scope      = scope
  @user_class = normalize_class(scope)
  @identifier = identifier
  @label      = label
  @base_scope = normalize_scope(base_scope)
end

Instance Attribute Details

#base_scopeObject (readonly)

Returns the value of attribute base_scope.



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

def base_scope
  @base_scope
end

#identifierObject (readonly)

Returns the value of attribute identifier.



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

def identifier
  @identifier
end

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#scopeObject (readonly)

Returns the value of attribute scope.



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

def scope
  @scope
end

#user_classObject (readonly)

Returns the value of attribute user_class.



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

def user_class
  @user_class
end

Class Method Details

.init_from_configObject



5
6
7
8
9
10
11
# File 'lib/switch_user/user_set.rb', line 5

def self.init_from_config
  SwitchUser.available_users.map do |scope, base_scope|
    identifier = SwitchUser.available_users_identifiers[scope]
    label      = SwitchUser.available_users_names[scope]
    new(scope, identifier, label, base_scope)
  end
end

.usersObject



13
14
15
16
17
# File 'lib/switch_user/user_set.rb', line 13

def self.users
  init_from_config.flat_map do |user_set|
    user_set.users.map { |user| Record.build(user, user_set) }
  end
end

Instance Method Details

#find_user(id) ⇒ Object Also known as: []



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

def find_user(id)
  Record.build(users.where(id: id).first, self)
end

#usersObject



33
34
35
# File 'lib/switch_user/user_set.rb', line 33

def users
  base_scope
end