Sha256: e82cf291bb100bca6bc3e9c1fa2582efaa04587b85dbfbdf64d4276e390a4a17

Contents?: true

Size: 596 Bytes

Versions: 1

Compression:

Stored size: 596 Bytes

Contents

module SwitchUser
  class UserLoader
    attr_reader :scope
    attr_accessor :id

    def initialize(scope, id)
      self.scope = scope
      self.id = id
    end

    def load
      user_class.send(finder, id)
    end

    private

    def scope=(scope)
      if SwitchUser.available_scopes.include?(scope.to_sym)
        @scope = scope
      else
        raise InvalidScope
      end
    end

    def user_class
      scope.classify.constantize
    end

    def finder
      column_name = SwitchUser.available_users_identifiers[scope.to_sym]

      "find_by_#{column_name}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
switch_user-0.9.0 lib/switch_user/user_loader.rb