1
0
Fork 0
forked from OpenNeo/impress
impress/app/models/zone.rb
Matchu 4f564db785 Upgrade to Rails 5.2.8.1
Some important little upgrades but mostly straightforward!

Note that there's still a known issue where item searches crash, I was hoping that this was a bug in Rails 4.2 that would be fixed on upgading to 5, but nope, oh well!

Also uhh I just got a bit silly and didn't actually mean to go all the way to 5.2 in one go, I had meant to start at 5.0… but tbh the 5.1 and 5.2 changes seem small, and this seems to be working, so. Yeah ok let's roll!
2023-08-02 16:05:09 -07:00

27 lines
865 B
Ruby

class Zone < ApplicationRecord
translates :label, :plain_label
# When selecting zones that an asset occupies, we allow the zone to set
# whether or not the zone is "sometimes" occupied. This is false by default.
attr_writer :sometimes
scope :alphabetical, -> {
with_translations(I18n.locale).order(Zone::Translation.arel_table[:label])
}
scope :includes_translations, -> { includes(:translations) }
scope :matching_label, ->(label, locale = I18n.locale) {
t = Zone::Translation.arel_table
joins(:translations)
.where(t[:locale].eq(locale))
.where(t[:plain_label].eq(Zone.plainify_label(label)))
}
scope :for_items, -> { where(arel_table[:type_id].gt(1)) }
def uncertain_label
@sometimes ? "#{label} sometimes" : label
end
def self.plainify_label(label)
label.delete('\- /').parameterize
end
end