Class: ThreeScale::Backend::Validators::Referrer

Inherits:
Base
  • Object
show all
Defined in:
lib/3scale/backend/validators/referrer.rb

Instance Attribute Summary

Attributes inherited from Base

#params, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#application, apply, #fail!, #initialize, #service, #succeed!

Constructor Details

This class inherits a constructor from ThreeScale::Backend::Validators::Base

Class Method Details

.behave_as_legacy(legacy) ⇒ Object



26
27
28
29
30
# File 'lib/3scale/backend/validators/referrer.rb', line 26

def behave_as_legacy(legacy)
  # don't blow up if we still didn't define it
  remove_method :pattern_matches? rescue NameError
  define_pattern_match legacy
end

.define_pattern_match(legacy) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/3scale/backend/validators/referrer.rb', line 11

def define_pattern_match(legacy)
  class_eval do
    if legacy
      def pattern_matches?(pattern, value)
        /#{pattern}/ =~ value
      end
    else
      def pattern_matches?(pattern, value)
        /\A#{pattern}\z/ =~ value
      end
    end
  end
end

Instance Method Details

#applyObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/3scale/backend/validators/referrer.rb', line 39

def apply
  if service.referrer_filters_required? && application.has_referrer_filters?
    if application.referrer_filters.any? { |filter| matches?(filter, params[:referrer]) }
      succeed!
    else
      fail!(ReferrerNotAllowed.new(params[:referrer]))
    end
  else
    succeed!
  end
end