Sha256: c953a01b5af717751499d8dc8d0fd813c2f6e85fc69b7b55533b5a605807424d

Contents?: true

Size: 884 Bytes

Versions: 2

Compression:

Stored size: 884 Bytes

Contents

module CopyleaksApi
  class Config
    DEFAULTS = {
      sandbox_mode: false,
      allow_partial_scan: false,
      http_callback: nil,
      email_callback: nil,
      custom_fields: {},
    }.freeze

    class << self
      attr_writer :sandbox_mode, :http_callback, :email_callback, :custom_fields, :allow_partial_scan

      DEFAULTS.each do |attr, value|
        # getters for all options
        define_method(attr) do
          var = instance_variable_get("@#{attr}")
          return var if var
          instance_variable_set("@#{attr}", value)
        end
      end

      # provide block syntax possibility for setting options
      def config
        yield(self)
      end

      # reset all options to default
      def reset
        DEFAULTS.each { |attr, value| instance_variable_set("@#{attr}", value) }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
plagiarism-checker-1.0.0 lib/copyleaks_api/config.rb
mkisilenko-test-0.1.0 lib/copyleaks_api/config.rb