Class: Library
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- 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
37 38 39 40 41 42 43 |
# File 'app/models/library.rb', line 37 def self.all_cache if Rails.env == 'production' Rails.cache.fetch('library_all'){ Library.all } else Library.all end end |
.web ⇒ Object
61 62 63 |
# File 'app/models/library.rb', line 61 def self.web Library.find(1) end |
Instance Method Details
#address(locale = I18n.locale) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/library.rb', line 65 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
76 77 78 79 |
# File 'app/models/library.rb', line 76 def address_changed? return true if region_changed? || locality_changed? || street_changed? false end |
#clear_all_cache ⇒ Object
45 46 47 |
# File 'app/models/library.rb', line 45 def clear_all_cache Rails.cache.delete('library_all') end |
#closed?(date) ⇒ Boolean
84 85 86 87 88 |
# File 'app/models/library.rb', line 84 def closed?(date) events.closing_days.map{ |c| c.start_at.beginning_of_day }.include?(date.beginning_of_day) end |
#create_shelf ⇒ Object
49 50 51 52 53 54 |
# File 'app/models/library.rb', line 49 def create_shelf shelf = Shelf.new shelf.name = "#{name}_default" shelf.library = self shelf.save! end |
#web? ⇒ Boolean
56 57 58 59 |
# File 'app/models/library.rb', line 56 def web? return true if id == 1 false end |