Module: AuthHelpers

Defined in:
lib/auth_helpers.rb,
lib/auth_helpers/notifier.rb,
lib/auth_helpers/spec/notifier.rb,
lib/auth_helpers/spec/updatable.rb,
lib/auth_helpers/model/updatable.rb,
lib/auth_helpers/spec/confirmable.rb,
lib/auth_helpers/spec/recoverable.rb,
lib/auth_helpers/model/confirmable.rb,
lib/auth_helpers/model/recoverable.rb,
lib/auth_helpers/controller/helpers.rb,
lib/auth_helpers/controller/confirmable.rb,
lib/auth_helpers/controller/recoverable.rb

Defined Under Namespace

Modules: Controller, Model, Spec Classes: Notifier

Class Method Summary collapse

Class Method Details

.find_or_initialize_by_unless_blank(klass, attr, value) ⇒ Object

Helper that find or initialize an object by attribute only if the given value is not blank. If it’s blank, create a new object using :new.



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

def self.find_or_initialize_by_unless_blank(klass, attr, value)
  if value.blank?
    klass.new
  else
    klass.send(:"find_or_initialize_by_#{attr}", value)
  end
end

.new_with_perishable_token_error(klass, message = :invalid, options = {}) ⇒ Object

Creates a new record, assigning the perishable token and an error message.



15
16
17
18
19
20
# File 'lib/auth_helpers.rb', line 15

def self.new_with_perishable_token_error(klass, message=:invalid, options={})
  record = klass.new(options)
  record.perishable_token = options[:perishable_token]
  record.errors.add(:perishable_token, :invalid, :default => message)
  record
end