Sha256: e30a7f9b73f61f8705d318d2fc8ce2fc6d81634c2a5e36213e2d00dcafc7d901
Contents?: true
Size: 817 Bytes
Versions: 5
Compression:
Stored size: 817 Bytes
Contents
require "uber/delegates" module Declarative class Defaults def initialize @static_options = {} end def merge!(hash, &block) @static_options.merge!(hash) if hash.any? @dynamic_options = block if block_given? self end extend Uber::Delegates delegates :@static_options, :[], :[]= # mutuable API! # TODO: allow to receive rest of options/block in dynamic block. or, rather, test it as it was already implemented. def call(name, given_options) options = @static_options options = options.merge(dynamic_options(name, given_options)) options = options.merge(given_options) end private def dynamic_options(name, given_options) return {} if @dynamic_options.nil? @dynamic_options.call(name, given_options) end end end
Version data entries
5 entries across 5 versions & 1 rubygems