Sha256: 7d29b389b923eaa600ac27eee14cd8588f737b4a15648957a4626f25663a046b

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

require 'active_support/all'
require 'i18n'

require 'protector/version'
require 'protector/dsl'
require 'protector/adapters/active_record'
require 'protector/adapters/sequel'

require 'protector/engine' if defined?(Rails)

I18n.load_path += Dir[File.expand_path File.join('..', 'locales', '*.yml'), File.dirname(__FILE__)]

module Protector
  class << self
    ADAPTERS = [
      Protector::Adapters::ActiveRecord,
      Protector::Adapters::Sequel
    ]

    attr_accessor :config

    def paranoid=
      '`Protector.paranoid = ...` is deprecated! Please change it to `Protector.config.paranoid = ...`'
    end

    # Allows executing any code having Protector globally disabled
    def insecurely(&block)
      Thread.current[:protector_disabled_nesting] ||= 0
      Thread.current[:protector_disabled_nesting] += 1

      Thread.current[:protector_disabled] = true
      yield
    ensure
      Thread.current[:protector_disabled_nesting] -= 1

      if Thread.current[:protector_disabled_nesting] == 0
        Thread.current[:protector_disabled] = false
      end
    end

    def activate!
      ADAPTERS.each { |adapter| adapter.activate! }
    end
  end

  # Internal protector config holder
  class Config < ActiveSupport::OrderedOptions
    def paranoid?
      !!paranoid
    end

    def strong_parameters?
      strong_parameters.nil? || !!strong_parameters
    end
  end

  self.config = Config.new
end

Protector.activate!

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
protector-0.7.7 lib/protector.rb
protector-0.7.6 lib/protector.rb
protector-0.7.4 lib/protector.rb
protector-0.7.3 lib/protector.rb
protector-0.7.2 lib/protector.rb
protector-0.7.1 lib/protector.rb
protector-0.7.0 lib/protector.rb