Farmbot-Web-App/app/models/device.rb

32 lines
744 B
Ruby
Raw Normal View History

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
class Device
include Mongoid::Document
2014-05-13 07:55:38 -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
has_one :planting_area
2014-05-13 07:55:38 -06:00
# The SkyNet UUID of the device
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
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
def if_not_null
yield(self)
self
end
def if_null
self
end
end