Class: Library

Inherits:
ApplicationRecord
  • Object
show all
Extended by:
FriendlyId
Includes:
MasterModel
Defined in:
app/models/library.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_cacheObject



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

.webObject



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

Returns:

  • (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_cacheObject



42
43
44
# File 'app/models/library.rb', line 42

def clear_all_cache
  Rails.cache.delete('library_all')
end

#closed?(date) ⇒ Boolean

Returns:

  • (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_shelfObject



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

Returns:

  • (Boolean)


53
54
55
56
# File 'app/models/library.rb', line 53

def web?
  return true if id == 1
  false
end