Module: Sinatra::Security::LoginField

Defined in:
lib/sinatra/security/login_field.rb

Overview

This module allows you to customize the name of the login field used in your datastore. By default :email is used.

Examples:


# somewhere in your code during bootstrapping
require 'sinatra/security'
Sinatra::Security::LoginField.attr_name :login

# then in your actual user.rb or something...
class User < Ohm::Model
  include Sinatra::Security::User
  # at this point the following are done:
  # attribute :login
  # index :login
end

Class Method Summary collapse

Class Method Details

.attr_nameSymbol .attr_name(attr_name) ⇒ Symbol

Returns the current attr_name.

Examples:


Sinatra::Security::LoginField.attr_name :username

class User < Ohm::Model
  include Sinatra::Security::User
  # effectively executes the following:
  # attribute :username
  # index :username
end

Overloads:

  • .attr_nameSymbol

    Get the value of attr_name.

  • .attr_name(attr_name) ⇒ Symbol

    Parameters:

    • attr_name (#to_sym)

      the attr_name to be used e.g. :username, :login.

Returns:

  • (Symbol)

    the current attr_name.



37
38
39
40
# File 'lib/sinatra/security/login_field.rb', line 37

def self.attr_name(attr_name = nil)
  @attr_name = attr_name.to_sym if attr_name
  @attr_name
end

.included(user) ⇒ Object



43
44
45
46
# File 'lib/sinatra/security/login_field.rb', line 43

def self.included(user)
  user.attribute LoginField.attr_name
  user.index     LoginField.attr_name
end