1 # frozen_string_literal: true
3 # == Schema Information
5 # Table name: moderation_zones
7 # id :bigint not null, primary key
8 # name :string not null
9 # reason :string not null
10 # reason_format :enum default("markdown")
11 # zone :st_polygon not null, polygon, 4326
13 # creator_id :bigint not null
15 # created_at :datetime not null
16 # updated_at :datetime not null
20 # index_moderation_zones_on_creator_id (creator_id)
21 # index_moderation_zones_on_revoker_id (revoker_id)
25 # fk_rails_... (creator_id => users.id)
26 # fk_rails_... (revoker_id => users.id)
28 class ModerationZone < ApplicationRecord
29 belongs_to :creator, :class_name => "User"
30 belongs_to :revoker, :class_name => "User", :optional => true
32 validates :name, :presence => true
33 validates :reason, :presence => true
34 validates :zone, :presence => true
36 def self.falls_within_any?(lon:, lat:)
37 factory = RGeo::Cartesian.simple_factory(:srid => 4326)
38 point = factory.point(lon, lat)
41 arel_table[:zone].st_contains(point)