From 1564af069472e32ed322bf9acedc9c487bce1a15 Mon Sep 17 00:00:00 2001 From: hellekin Date: Tue, 6 Oct 2020 19:29:04 +0200 Subject: First pass at listing Resources This implements resource listing and pagination. See /resources --- app/models/resource.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'app/models') diff --git a/app/models/resource.rb b/app/models/resource.rb index ba3dd1f..e67d164 100644 --- a/app/models/resource.rb +++ b/app/models/resource.rb @@ -3,4 +3,23 @@ class Resource < ApplicationRecord include UUIDParameter belongs_to :agent + + # Figure out the requested property name + def method_missing(name, *args, &block) + Rails.logger.info("method_missing: #{name} // #{feature['properties'][name.to_s]}") + if feature['properties'].key?(name.to_s) + feature['properties'][name.to_s] + else + case name.to_s + when 'lon', 'longitude' + feature['geometry']['coordinates'].first + when 'lat', 'latitude' + feature['geometry']['coordinates'].last + when 'geo_type' + feature['geometry']['type'] + else + super + end + end + end end -- cgit v1.2.3