Sha256: 86d669066e1ada7895439d8872a1f9cd970a8bf9044fc34002820b43453f2ef8

Contents?: true

Size: 843 Bytes

Versions: 3

Compression:

Stored size: 843 Bytes

Contents

module Findable
  class Configuration
    VALID_OPTIONS = [
      :redis_options,
      :seed_file
    ].freeze

    attr_accessor *VALID_OPTIONS

    def initialize
      reset
    end

    def configure
      yield self
    end

    def merge(params)
      self.dup.merge!(params)
    end

    def merge!(params)
      params.keys.each {|key| self.send("#{key}=", params[key]) }
      self
    end

    def reset
      self.redis_options = nil
      self.seed_file = defined?(Rails) ? Rails.root.join("db", "findable_seeds.rb") : nil
    end

    module Accessible
      def configure(options = {}, &block)
        config.merge!(options) unless options.empty?
        config.configure(&block) if block_given?
      end

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

  extend Configuration::Accessible
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
findable-0.0.3 lib/findable/configuration.rb
findable-0.0.2 lib/findable/configuration.rb
findable-0.0.1 lib/findable/configuration.rb