Class: CASinoCore::Model::ServiceRule

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/casino_core/model/service_rule.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allowed?(service_url) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'lib/casino_core/model/service_rule.rb', line 8

def self.allowed?(service_url)
  rules = self.where(enabled: true)
  if rules.empty?
    true
  else
    rules.any? { |rule| rule.allows?(service_url) }
  end
end

Instance Method Details

#allows?(service_url) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/casino_core/model/service_rule.rb', line 17

def allows?(service_url)
  if self.regex?
    regex = Regexp.new self.url, true
    if regex =~ service_url
      return true
    end
  elsif self.url == service_url
    return true
  end
  false
end