class Hydra::IpBasedGroups

Public Class Methods

filename() click to toggle source
# File lib/hydra/ip_based_groups.rb, line 32
def self.filename
  'config/hydra_ip_range.yml'
end
for(remote_ip) click to toggle source
# 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
groups() click to toggle source
# File lib/hydra/ip_based_groups.rb, line 28
def self.groups
  load_groups.fetch('groups').map { |h| Group.new(h) }
end
load_groups() click to toggle source
# File lib/hydra/ip_based_groups.rb, line 36
def self.load_groups
  require 'yaml'

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

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

  begin
    yml = if Psych::VERSION > '4.0'
      YAML.safe_load(File.read(file), aliases: true)
    else
      YAML.safe_load(File.read(file), [], [], true)
    end
  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