Sha256: 647cd416480f1cbd8bace806e41831b53ba0fbe160af0a1e8ab7316050249440

Contents?: true

Size: 819 Bytes

Versions: 5

Compression:

Stored size: 819 Bytes

Contents

module SwitchUserHelper
  SelectOption = Struct.new(:label, :scope_id)
  def switch_user_select
    return unless available?

    if provider.current_user
      selected_user = "user_#{current_user.id}"
    else
      selected_user = nil
    end

    render :partial => "switch_user/widget",
           :locals => {
             :options => SwitchUser.all_users,
             :current_scope => selected_user
           }
  end

  private

  def user_tag_value(user, id_name, scope)
    identifier = user.send(id_name)

    "#{scope}_#{identifier}"
  end

  def user_tag_label(user, name)
    name.respond_to?(:call) ? name.call(user) : user.send(name)
  end

  def available?
    SwitchUser.guard_class.new(controller, provider).view_available?
  end

  def provider
    SwitchUser::Provider.init(controller)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
switch_user-1.1.0 app/helpers/switch_user_helper.rb
switch_user-1.0.2 app/helpers/switch_user_helper.rb
switch_user-1.0.1 app/helpers/switch_user_helper.rb
switch_user-1.0.0 app/helpers/switch_user_helper.rb
switch_user-0.9.5 app/helpers/switch_user_helper.rb