Sha256: 63cccb878b104b874c5907325779580fc711eaa0069269e62a1befaede2f7deb
Contents?: true
Size: 1.65 KB
Versions: 10
Compression:
Stored size: 1.65 KB
Contents
# frozen_string_literal: true require 'kind/__lib__/kind' require 'kind/__lib__/undefined' module Kind module ATTRIBUTES extend self def name!(name) STRICT.kind_of(::Symbol, name) end def value(kind, default, visibility = :private) [kind, default, visibility] end def value_to_assign(kind, default, hash, name) raw_value = hash[name] return raw_value if kind.nil? && UNDEFINED == default value = resolve_value_to_assign(kind, default, raw_value) (kind.nil? || kind === value) ? value : nil end def value!(kind, default) return value(kind, default) unless kind.nil? raise Error.new("kind expected to not be nil") end def value_to_assign!(kind, default, hash, name) value = resolve_value_to_assign(kind, default, hash[name]) Kind.of(kind, value, label: name) end private def resolve_value_to_assign(kind, default, value) if kind == ::Proc UNDEFINED == default ? value : KIND.value(kind, value, default) else default_is_a_callable = default.respond_to?(:call) default_value = if default_is_a_callable default_fn = Proc === default ? default : default.method(:call) default_fn.arity != 0 ? default_fn.call(value) : default_fn.call else default end return value if UNDEFINED == default_value return default_value || value if kind.nil? default_is_a_callable ? KIND.value(kind, default_value, value) : KIND.value(kind, value, default_value) end end end private_constant :ATTRIBUTES end
Version data entries
10 entries across 10 versions & 1 rubygems