Class: SupplejackApi::HarvesterConstraint
- Inherits:
-
Object
- Object
- SupplejackApi::HarvesterConstraint
- Defined in:
- lib/supplejack_api/harvester_constraint.rb
Instance Method Summary collapse
- #forwarded_ips(request) ⇒ Object
-
#initialize ⇒ HarvesterConstraint
constructor
A new instance of HarvesterConstraint.
- #matches?(request) ⇒ Boolean
Constructor Details
#initialize ⇒ HarvesterConstraint
Returns a new instance of HarvesterConstraint.
11 12 13 14 15 16 |
# File 'lib/supplejack_api/harvester_constraint.rb', line 11 def initialize @ips = ENV['HARVESTER_IPS'].gsub(/\s+/, '').split(',') rescue # Allow supplejack:install generator to work without application.yml file @ips = ['127.0.0.1'] end |
Instance Method Details
#forwarded_ips(request) ⇒ Object
23 24 25 26 |
# File 'lib/supplejack_api/harvester_constraint.rb', line 23 def forwarded_ips(request) ip_addresses = request.env['HTTP_X_FORWARDED_FOR'] ip_addresses ? ip_addresses.strip.split(/[,\s]+/) : [] end |
#matches?(request) ⇒ Boolean
18 19 20 21 |
# File 'lib/supplejack_api/harvester_constraint.rb', line 18 def matches?(request) forwarded_ips(request).each { |ip| return false unless @ips.include?(ip) } @ips.include?(request.remote_ip) end |