Sha256: ce8314d80d627e344ae678beef63046fb686d14cf69b0f72bfaf05125b0296db

Contents?: true

Size: 751 Bytes

Versions: 1

Compression:

Stored size: 751 Bytes

Contents

# frozen_string_literal: true

require 'ostruct'

module BusinessPipeline
  class Config
    def initialize(hash = nil, &block)
      @data = OpenStruct.new(hash)

      instance_eval(&block) if block
    end

    def fetch(key)
      value = data[key.to_sym]

      return value unless value.nil?
      return yield(key) if block_given?

      fail KeyError, key
    end

    def method_missing(meth, *args, &block)
      if args.size.zero? || meth.to_s.end_with?('=')
        data.public_send(meth, *args, &block)
      else
        data[meth] = args.first
      end
    end

    def respond_to_missing?(meth, include_private = false)
      data.respond_to?(meth, include_private) || super
    end

    attr_reader :data
    private :data
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
business_pipeline-0.3.1 lib/business_pipeline/config.rb