FarmBot/Farmbot-Web-App

View on GitHub
app/models/point_group.rb

Summary

Maintainability
A
0 mins
Test Coverage
class PointGroup < ApplicationRecord
  SORT_TYPES =
    %w(xy_ascending xy_descending yx_ascending yx_descending xy_alternating yx_alternating nn random).sort
  BAD_SORT = "%{value} is not valid. Valid options are: " +
             SORT_TYPES.map(&:inspect).join(", ")
  DEFAULT_CRITERIA = {
    day: { op: "<", days_ago: 0 },
    string_eq: {},
    number_eq: {},
    number_lt: {},
    number_gt: {},
  }

  belongs_to :device
  has_many :point_group_items, dependent: :destroy
  validates_inclusion_of :sort_type, in: SORT_TYPES,
                                     message: BAD_SORT
  serialize :criteria
end