Class: Hydra::IpBasedGroups

Inherits:
Object
  • Object
show all
Defined in:
lib/hydra/ip_based_groups.rb

Defined Under Namespace

Classes: Group

Class Method Summary collapse

Class Method Details

.filenameObject



32
33
34
# File 'lib/hydra/ip_based_groups.rb', line 32

def self.filename
  'config/hydra_ip_range.yml'
end

.for(remote_ip) ⇒ Object



4
5
6
# File 'lib/hydra/ip_based_groups.rb', line 4

def self.for(remote_ip)
  groups.select { |group| group.include_ip?(remote_ip) }.map(&:name)
end

.groupsObject



28
29
30
# File 'lib/hydra/ip_based_groups.rb', line 28

def self.groups
  load_groups.fetch('groups').map { |h| Group.new(h) }
end

.load_groupsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hydra/ip_based_groups.rb', line 36

def self.load_groups
  require 'yaml'

  file = File.join(Rails.root, filename)

  unless File.exists?(file)
    raise "ip-range configuration file not found. Expected: #{file}."
  end

  begin
    yml = YAML::load_file(file)
  rescue
    raise("#{filename} was found, but could not be parsed.\n")
  end
  unless yml.is_a? Hash
    raise("#{filename} was found, but was blank or malformed.\n")
  end

  yml.fetch(Rails.env)
end