Class: ActiveAccess::Utility::Config

Inherits:
HashMapper
  • Object
show all
Defined in:
lib/active-access/utility/config.rb

Constant Summary

Constants inherited from HashMapper

HashMapper::ALLOWED_SUFFIXES

Instance Method Summary collapse

Methods inherited from HashMapper

#key?, #method_missing, #respond_to_missing?, #update!

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active-access/utility/config.rb', line 8

def initialize(*)
  super

  domains                   = protected_domains
  good_urls                 = whitelisted_urls
  self["protected_domains"] = {}
  self["whitelisted_urls"]  = {}

  self.whitelisted_urls  = good_urls
  self.protected_domains = domains
  self.allowed_ips       = allowed_ips
  self.enabled           = true if enabled.nil?
  self.message           = "Resource Not Found" if message.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveAccess::Utility::HashMapper

Instance Method Details

#allowed_ips=(ip_addresses) ⇒ Object



23
24
25
# File 'lib/active-access/utility/config.rb', line 23

def allowed_ips=(ip_addresses)
  self["allowed_ips"] = Set.new(split_or_ship(ip_addresses))
end

#protected_domains=(domains) ⇒ Object



27
28
29
30
# File 'lib/active-access/utility/config.rb', line 27

def protected_domains=(domains)
  return if domains.blank?
  split_or_ship(domains).each { |domain| self["protected_domains"][strip_url(domain)] = true }
end

#strip_url(url) ⇒ Object



41
42
43
# File 'lib/active-access/utility/config.rb', line 41

def strip_url(url)
  url.to_s.sub(%r{^https?\:\/\/(www.)?}, "")
end

#whitelisted_urls=(url_sets) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/active-access/utility/config.rb', line 32

def whitelisted_urls=(url_sets)
  return if url_sets.blank?
  split_or_ship(url_sets).each do |url_set|
    url, request_method = url_set
    next if url.blank?
    self["whitelisted_urls"][strip_url(url)] = request_method.nil? ? "GET" : request_method.to_s.upcase
  end
end