Class: Device
- Inherits:
-
Object
- Object
- Device
- Includes:
- CheckinAble, Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/models/device.rb
Overview
Holds a single device, where a device may have many agents (and thus apps) installed on it.
-
Data comes in as device_platform, device_os_version, device_model, device_manufacture, device_capacity, app_version
-
Raw model id is saved on internal_model if updated from market name
-
Add app ids to app_ids, need to copy over app_id array and delete it
-
Remove identifier
Class Method Summary collapse
-
.fetch(json) ⇒ Object
Fetch or create a device.
Instance Method Summary collapse
-
#filter_json(json) ⇒ Object
filter only the json parameters we want to take into the device.
-
#update!(attributes = {}) ⇒ Object
Safely update attributes from the document.
-
#update_attributes!(attributes = {}) ⇒ Object
Safely update attributes from the document.
Methods included from CheckinAble
Class Method Details
.fetch(json) ⇒ Object
Fetch or create a device
42 43 44 45 46 47 48 49 |
# File 'lib/models/device.rb', line 42 def self.fetch(json) device_identifier = json[:device_identifier] raise 'device_id cannot be nil' if device_identifier.nil? device = Device.find_or_initialize_by(unique_identifier: device_identifier) device.update_attributes!(json) device end |
Instance Method Details
#filter_json(json) ⇒ Object
filter only the json parameters we want to take into the device. The agent sends up more than we need for the device.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/models/device.rb', line 69 def filter_json(json) filtered_json = {} filtered_json[:platform] = json[:device_platform] if json[:device_platform] filtered_json[:os_version] = json[:device_os_version] if json[:device_os_version] filtered_json[:manufacture] = json[:device_manufacture] if json[:device_manufacture] filtered_json[:capacity] = json[:device_capacity] if json[:device_capacity] filtered_json[:model] = json[:device_model] if json[:device_model] filtered_json[:name] = json[:device_name] if json[:device_name] filtered_json end |
#update!(attributes = {}) ⇒ Object
Safely update attributes from the document
61 62 63 |
# File 'lib/models/device.rb', line 61 def update!(attributes = {}) super(filter_json(attributes)) end |
#update_attributes!(attributes = {}) ⇒ Object
Safely update attributes from the document
54 55 56 |
# File 'lib/models/device.rb', line 54 def update_attributes!(attributes = {}) super(filter_json(attributes)) end |