2014-05-10 21:00:13 -06:00
|
|
|
# FarmbotDevice models all data related to an actual FarmBot in the real world.
|
|
|
|
# This is useful for caching things like SkyNey IDs, owner users, work logs, etc
|
2014-05-12 08:23:35 -06:00
|
|
|
class Device
|
2014-05-09 07:48:18 -06:00
|
|
|
include Mongoid::Document
|
2014-05-13 07:55:38 -06:00
|
|
|
|
2015-07-08 08:32:35 -06:00
|
|
|
has_many :users
|
|
|
|
has_many :schedules, dependent: :destroy
|
|
|
|
has_many :sequences
|
2015-09-30 13:24:15 -06:00
|
|
|
has_many :plants, dependent: :destroy
|
2015-10-05 07:38:26 -06:00
|
|
|
has_one :planting_area
|
2015-07-08 08:32:35 -06:00
|
|
|
|
2014-05-12 08:23:35 -06:00
|
|
|
|
2014-05-13 07:55:38 -06:00
|
|
|
# The SkyNet UUID of the device
|
2014-05-12 08:23:35 -06:00
|
|
|
field :uuid
|
2014-05-14 07:55:07 -06:00
|
|
|
validates :uuid, presence: true
|
2014-05-13 07:55:38 -06:00
|
|
|
# The SkyNet Authentication token for the device
|
2014-05-12 08:23:35 -06:00
|
|
|
field :token
|
2014-05-14 07:55:07 -06:00
|
|
|
validates :token, presence: true
|
2014-05-13 07:55:38 -06:00
|
|
|
# The 'Friendly Name' of the device. I recommend 'The Cabbage Patch Kid'
|
|
|
|
field :name
|
2014-05-14 07:55:07 -06:00
|
|
|
validates :name, presence: true
|
2015-07-09 08:22:24 -06:00
|
|
|
|
|
|
|
def if_not_null
|
|
|
|
yield(self)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def if_null
|
|
|
|
self
|
|
|
|
end
|
2014-05-09 07:48:18 -06:00
|
|
|
end
|