Sha256: 213921937b75538e8d9129d26a1436512250d5b724bd7eff482ff059e5890f9c

Contents?: true

Size: 918 Bytes

Versions: 23

Compression:

Stored size: 918 Bytes

Contents

# frozen_string_literal: true

# TODO: move to Praxis proper...it's not used here
module Praxis
  class ConfigHash < BasicObject
    attr_reader :hash

    def self.from(hash = {}, &block)
      new(hash, &block)
    end

    def initialize(hash = {}, &block)
      @hash = hash
      @block = block
    end

    def to_hash
      instance_eval(&@block)
      @hash
    end

    def respond_to_missing?(_method_name, _include_private = false)
      true
    end

    def method_missing(name, value, *rest, &block)
      if (existing = @hash[name])
        if block
          existing << [value, block]
        else
          existing << value
          rest.each do |v|
            existing << v
          end
        end
      else
        @hash[name] = if rest.any?
                        [value] + rest
                      else
                        value
                      end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
praxis-2.0.0 lib/praxis/config_hash.rb
praxis-2.0.pre.40 lib/praxis/config_hash.rb
praxis-2.0.pre.39 lib/praxis/config_hash.rb
praxis-2.0.pre.38 lib/praxis/config_hash.rb
praxis-2.0.pre.37 lib/praxis/config_hash.rb
praxis-2.0.pre.36 lib/praxis/config_hash.rb
praxis-2.0.pre.35 lib/praxis/config_hash.rb
praxis-2.0.pre.34 lib/praxis/config_hash.rb
praxis-2.0.pre.33 lib/praxis/config_hash.rb
praxis-2.0.pre.32 lib/praxis/config_hash.rb
praxis-2.0.pre.31 lib/praxis/config_hash.rb
praxis-2.0.pre.30 lib/praxis/config_hash.rb
praxis-2.0.pre.29 lib/praxis/config_hash.rb
praxis-2.0.pre.28 lib/praxis/config_hash.rb
praxis-2.0.pre.27 lib/praxis/config_hash.rb
praxis-2.0.pre.26 lib/praxis/config_hash.rb
praxis-2.0.pre.25 lib/praxis/config_hash.rb
praxis-2.0.pre.24 lib/praxis/config_hash.rb
praxis-2.0.pre.23 lib/praxis/config_hash.rb
praxis-2.0.pre.22 lib/praxis/config_hash.rb