Class: ThreeScale::Backend::Validators::Referrer
- Inherits:
-
Base
- Object
- Base
- ThreeScale::Backend::Validators::Referrer
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!
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)
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
#apply ⇒ Object
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
|