Sha256: ff83cb1ad3413bd48b5c4138565cb04eedb04ee30c71e6234a34b207f823aa50

Contents?: true

Size: 952 Bytes

Versions: 1

Compression:

Stored size: 952 Bytes

Contents

require "rehearsal/version"
require "rehearsal/engine"

module Rehearsal
  def self.included(base)
    base.extend ClassMethods
    base.helper_method :rehearsing?
    base.before_filter :require_http_basic_auth
  end

  module ClassMethods
    def rehearse_with(options = {})
      class_eval do
        define_method(:username) do
          options[:username]
        end

        define_method(:password) do
          options[:password]
        end
      end
    end
  end

  class << self
    def configure
      yield(config)
    end

    def config=(config_instance)
      @config = config_instance
    end

    def config
      @config ||= Configuration.new
    end
  end

  private
  def require_http_basic_auth
    authenticate_or_request_with_http_basic do |username, password|
      username == self.username && password == self.password
    end if rehearsing?
  end

  def rehearsing?
    Rails.env.to_sym == Rehearsal.config.env
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rehearsal-1.0.0 lib/rehearsal.rb