Class: Library
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Library
- Extended by:
- FriendlyId
- Includes:
- MasterModel
- Defined in:
- app/models/library.rb
Class Method Summary collapse
Instance Method Summary collapse
- #address(locale = I18n.locale) ⇒ Object
- #address_changed? ⇒ Boolean
- #clear_all_cache ⇒ Object
- #closed?(date) ⇒ Boolean
- #create_shelf ⇒ Object
- #web? ⇒ Boolean
Class Method Details
.all_cache ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/library.rb', line 34 def self.all_cache if Rails.env == 'production' Rails.cache.fetch('library_all'){ Library.all } else Library.all end end |
.web ⇒ Object
58 59 60 |
# File 'app/models/library.rb', line 58 def self.web Library.find(1) end |
Instance Method Details
#address(locale = I18n.locale) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/library.rb', line 62 def address(locale = I18n.locale) case locale.to_sym when :ja "#{region.to_s.localize(locale)}#{locality.to_s.localize(locale)}#{street.to_s.localize(locale)}" else "#{street.to_s.localize(locale)} #{locality.to_s.localize(locale)} #{region.to_s.localize(locale)}" end rescue Psych::SyntaxError nil end |
#address_changed? ⇒ Boolean
73 74 75 76 |
# File 'app/models/library.rb', line 73 def address_changed? return true if saved_change_to_region? || saved_change_to_locality? || saved_change_to_street? false end |
#clear_all_cache ⇒ Object
42 43 44 |
# File 'app/models/library.rb', line 42 def clear_all_cache Rails.cache.delete('library_all') end |
#closed?(date) ⇒ Boolean
81 82 83 84 85 |
# File 'app/models/library.rb', line 81 def closed?(date) events.closing_days.map{ |c| c.start_at.beginning_of_day }.include?(date.beginning_of_day) end |
#create_shelf ⇒ Object
46 47 48 49 50 51 |
# File 'app/models/library.rb', line 46 def create_shelf shelf = Shelf.new shelf.name = "#{name}_default" shelf.library = self shelf.save! end |
#web? ⇒ Boolean
53 54 55 56 |
# File 'app/models/library.rb', line 53 def web? return true if id == 1 false end |