Class: UserDevice

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps, Searchable
Defined in:
lib/models/user_device.rb

Overview

Device associated with a user’s install of the app store. Held within the user object itself as an embedded document

Constant Summary collapse

ENROLLING =

Constants

'enrolling'
REGISTERING =
'registering'
AUTHORIZING =
'authorizing'
UNREGISTERED =
'unregistered'
PENDING =
'pending'
REJECTED =
'rejected'
APPROVED =
'approved'
REMOVED =
'removed'
DEREGISTERED =
'deregistered'
KEEP_STATES =
[UNREGISTERED, PENDING, REJECTED, APPROVED].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Searchable

included

Class Method Details

.find_device_by(device_id) ⇒ Object

Find a user device by safely trying a number of approaches

  1. By ID

  2. By unique identifier

  3. By app47 identifier

  4. By token



73
74
75
76
77
78
79
80
81
82
# File 'lib/models/user_device.rb', line 73

def self.find_device_by(device_id)
  raise 'Invalid ID' if device_id.blank?

  UserDevice.where(_id: device_id).first ||
    UserDevice.where(unique_identifier: device_id).first ||
    UserDevice.where(app47_identifier: device_id).first ||
    UserDevice.where(token: device_id).first
rescue StandardError
  nil
end

Instance Method Details

#approved?Boolean

Is the device approved?

Returns:

  • (Boolean)


62
63
64
# File 'lib/models/user_device.rb', line 62

def approved?
  UserDevice::APPROVED.eql? state
end

#search_fieldsObject

Define which fields to include in search text



55
56
57
# File 'lib/models/user_device.rb', line 55

def search_fields
  %w[state platform model manufacture os_version description]
end