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.



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

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.



17
18
19
# File 'lib/switch_user/user_set.rb', line 17

def base_scope
  @base_scope
end

#identifierObject (readonly)

Returns the value of attribute identifier.



17
18
19
# File 'lib/switch_user/user_set.rb', line 17

def identifier
  @identifier
end

#labelObject (readonly)

Returns the value of attribute label.



17
18
19
# File 'lib/switch_user/user_set.rb', line 17

def label
  @label
end

#scopeObject (readonly)

Returns the value of attribute scope.



17
18
19
# File 'lib/switch_user/user_set.rb', line 17

def scope
  @scope
end

#user_classObject (readonly)

Returns the value of attribute user_class.



17
18
19
# File 'lib/switch_user/user_set.rb', line 17

def user_class
  @user_class
end

Class Method Details

.init_from_configObject



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

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



11
12
13
14
15
# File 'lib/switch_user/user_set.rb', line 11

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

Instance Method Details

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



26
27
28
# File 'lib/switch_user/user_set.rb', line 26

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

#usersObject



31
32
33
# File 'lib/switch_user/user_set.rb', line 31

def users
  base_scope
end