Class: Hydra::IpBasedGroups
- Inherits:
-
Object
- Object
- Hydra::IpBasedGroups
- Defined in:
- lib/hydra/ip_based_groups.rb
Defined Under Namespace
Classes: Group
Class Method Summary collapse
Class Method Details
.filename ⇒ Object
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 |
.groups ⇒ Object
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_groups ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 |