[STABLE] Fix breakages. TODO: Continue hard/soft point limits

pull/1109/head
Rick Carlino 2019-02-08 14:20:40 -06:00
parent 2cdb75207f
commit 2785563e21
4 changed files with 56 additions and 25 deletions

View File

@ -1,22 +1,50 @@
module Resources
DEVICE_REGEX = /device_\d*/
ACTIONS = [ DESTROY = "destroy", SAVE = "save" ]
# Resources eligibile for the MQTT-based APIs
ELIGIBLE_RESOURCES = [ FarmEvent,
FarmwareInstallation,
Image,
Log,
Peripheral,
PinBinding,
PlantTemplate,
Point,
Regimen,
SavedGarden,
Sensor,
SensorReading,
Sequence,
Tool,
WebcamFeed, ]
# Map stringy class names to real classes
RESOURCES = \
ELIGIBLE_RESOURCES.reduce({}) do |acc, klass|
acc[klass.to_s] = klass
acc
end
RESOURCES = { # Because I don't trust Kernel.const_get
"FarmEvent" => FarmEvent,
"FarmwareInstallations" => FarmwareInstallation,
"Image" => Image,
"Log" => Log,
"Peripheral" => Peripheral,
"PinBinding" => PinBinding,
"PlantTemplate" => PlantTemplate,
"Point" => Point,
"Regimen" => Regimen,
"SavedGarden" => SavedGarden,
"Sensor" => Sensor,
"SensorReading" => SensorReading,
"Sequence" => Sequence,
"Tool" => Tool,
"WebcamFeed" => WebcamFeed,
# Map ActiveRecord class to a Mutations::Command class.
MUTATION_MAPPING = {
FarmEvent => FarmEvents,
FarmwareInstallations => FarmwareInstallations,
Image => Images,
Log => Logs,
Peripheral => Peripherals,
PinBinding => PinBindings,
PlantTemplate => PlantTemplates,
Regimen => Regimens,
SavedGarden => SavedGardens,
Sensor => Sensors,
SensorReading => SensorReadings,
Sequence => Sequences,
Tool => Tools,
WebcamFeed => WebcamFeeds,
# SPECIAL CASES =============================
# These reasources don't follow usual
# naming coonventions.
Plants => Points,
Point => Points,
ToolSlot => Points,
}
end # Resources

View File

@ -1,6 +1,7 @@
module Resources
class Job < Mutations::Command
NOT_FOUND = "Resource not found"
required do
duck :body, methods: [:[], :[]=]
duck :resource, duck: [:where, :find_by]

View File

@ -18,9 +18,10 @@ module Resources
end
required do
string :action, in: ACTIONS # "destroy"
string :device_name, matches: DEVICE_REGEX # "device_3"
string :resource, in: RESOURCES.keys # "Sequence"
string :action, in: ACTIONS # "destroy"
string :device_name, matches: DEVICE_REGEX # "device_3"
# "Sequence":
string :resource, in: ELIGIBLE_RESOURCES.map(&:to_s)
end
optional do

View File

@ -137,12 +137,13 @@ describe Resources::Job do
it "creates a point" do
device = FactoryBot.create(:device)
body = { name: SecureRandom.uuid,
x: 1,
y: 1,
z: 1,
radius: 1,
meta: {} }
body = { name: SecureRandom.uuid,
x: 1,
y: 1,
z: 1,
radius: 1,
meta: {},
pointer_type: "GenericPointer" }
result = Resources::Job.run!(body: body,
resource: Point,
resource_id: 0,