Sha256: cda48a33319491c8df5f668a189ad84b80affc64ea5c3a319905e0fe5826c746

Contents?: true

Size: 580 Bytes

Versions: 4

Compression:

Stored size: 580 Bytes

Contents

class CASino::ServiceRule < ActiveRecord::Base
  validates :name, presence: true
  validates :url, uniqueness: true, presence: true

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

  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
casino-4.1.2 app/models/casino/service_rule.rb
casino-4.1.1 app/models/casino/service_rule.rb
casino-4.1.0 app/models/casino/service_rule.rb
casino-4.0.3 app/models/casino/service_rule.rb