Class: LibraryGroup

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
MasterModel
Defined in:
app/models/library_group.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.site_configObject



31
32
33
# File 'app/models/library_group.rb', line 31

def self.site_config
  LibraryGroup.find(1)
end

.system_name(locale = I18n.locale) ⇒ Object



35
36
37
# File 'app/models/library_group.rb', line 35

def self.system_name(locale = I18n.locale)
  LibraryGroup.site_config.display_name.localize(locale)
end

Instance Method Details

#config?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/library_group.rb', line 39

def config?
  true if self == LibraryGroup.site_config
end

#network_access_allowed?(ip_address, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/library_group.rb', line 48

def network_access_allowed?(ip_address, options = {})
  options = { network_type: :lan }.merge(options)
  client_ip = IPAddr.new(ip_address)
  case options[:network_type]
  when :admin
    allowed_networks = admin_networks.to_s.split
  else
    allowed_networks = my_networks.to_s.split
  end
  allowed_networks.each do |allowed_network|
    begin
      network = IPAddr.new(allowed_network)
      return true if network.include?(client_ip)
    rescue ArgumentError
      nil
    end
  end
  return false
end

#real_librariesObject



43
44
45
46
# File 'app/models/library_group.rb', line 43

def real_libraries
  # 物理的な図書館 = IDが1以外
  libraries.where('id != 1').all
end

#userObject



68
69
70
# File 'app/models/library_group.rb', line 68

def user
  User.find(1)
end