Sha256: 3fce6a31f700e1678811a44987caed05fd37729c26549c37f79ae6de46774079

Contents?: true

Size: 947 Bytes

Versions: 4

Compression:

Stored size: 947 Bytes

Contents

module Findable
  class Configuration
    VALID_OPTIONS = [
      :redis_options,
      :seed_dir,
      :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_dir = defined?(Rails) ? Rails.root.join("db", "findable_seeds") : 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

4 entries across 4 versions & 1 rubygems

Version Path
findable-0.1.3 lib/findable/configuration.rb
findable-0.1.2 lib/findable/configuration.rb
findable-0.1.1 lib/findable/configuration.rb
findable-0.1.0 lib/findable/configuration.rb