Module: Devise::Models::Latcheable

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise_latcheable/model.rb

Instance Method Summary collapse

Instance Method Details

#latch_enableObject



75
76
77
78
79
# File 'lib/devise_latcheable/model.rb', line 75

def latch_enable
  if ::DeviseLatcheable.config['always_enabled'] == true
    self.latch_enabled = true
  end
end

#latch_enabled?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/devise_latcheable/model.rb', line 18

def latch_enabled?
  latch_enabled
end

#latch_pair!Object

> Pairs an user with the server.

If an error occurs, it copies the error at errors base
so you can access it with model_instance.errors
On success, it sets  to the value that
latch server sent on its response
@returns true on success, false otherwise


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/devise_latcheable/model.rb', line 62

def latch_pair!
  return true unless latch_enabled?
  api_response = ::DeviseLatcheable.api.pair latch_pair_code

  if api_response.error.nil?
    self. = api_response.data['accountId']
    return true
  else
    errors.add(:base, "Latch error: #{api_response.error.message}")
    return false
  end
end

#latch_unlocked?Boolean

> Checks if the app lock is open

@returns true if the latch is unlocked
@returns false if the latch is locked or if there was an error

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/devise_latcheable/model.rb', line 25

def latch_unlocked?
  return true unless latch_enabled?
  return false if .nil?
  api_response = ::DeviseLatcheable.api.status 

  if api_response.error.nil?
    key = api_response.data['operations'].keys.first
    status = api_response.data['operations'][key]['status']
    return (status == 'on')
  else
    return false
  end
end

#latch_unpair!Object

> Removes the pairing from latch

If an error occurs, it copies the error at errors base
so you can access it with model_instance.errors
@returns true on success, false otherwise


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/devise_latcheable/model.rb', line 43

def latch_unpair!
  return true unless latch_enabled?
  return true if .nil?
  api_response = ::DeviseLatcheable.api.unpair 

  if api_response.error.nil?
    return true
  else
    errors.add(:base, "Latch error: #{api_response.error.message}")
    return false
  end
end