Sha256: bf6450a587d8c615dd57b693a737937e75c255f04b31cd1be69b336678723ccc

Contents?: true

Size: 954 Bytes

Versions: 7

Compression:

Stored size: 954 Bytes

Contents

require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/object/blank'

module BitzerStore
  class Configure
    def self.setting(config)
      raise ArgumentError, "block not supplied" unless block_given?
      c = Configure.new
      yield(c)
      config.cache_store = :bitzer_store, c.settings
    end

    attr_reader :settings

    def initialize
      @settings = {}
    end

    def set(name, *args)
      options = common_options.merge(args.extract_options!)
      args = args.presence || common_args
      args = args + [options] if options.present?

      @settings[name] = args
    end

    def method_missing(name, *args, &block)
      set(name, *args)
    end

    def common_setting(*args)
      @common_options = args.extract_options!
      @common_args = args
    end

    private

    def common_args
      @common_args || []
    end

    def common_options
      @common_options || {}
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bitzer_store-1.1.1 lib/bitzer_store/configure.rb
bitzer_store-1.1.0 lib/bitzer_store/configure.rb
bitzer_store-1.0.3 lib/bitzer_store/configure.rb
bitzer_store-1.0.2 lib/bitzer_store/configure.rb
bitzer_store-1.0.1 lib/bitzer_store/configure.rb
bitzer_store-1.0.0 lib/bitzer_store/configure.rb
bitzer_store-0.0.3 lib/bitzer_store/configure.rb