Sha256: 4d036ce25412da1031c31249c7c8e21e820a9d5d4d13aa9740ebd9b6a7ea2848
Contents?: true
Size: 936 Bytes
Versions: 2
Compression:
Stored size: 936 Bytes
Contents
module NsOptions module Helper module_function # Common method for creating a new namespace def new_namespace(key, parent = nil, &block) namespace = NsOptions::Namespace.new(key, parent) namespace.define(&block) end # Common method for creating a new child namespace, using the owner's class's options as the # parent. def new_child_namespace(owner, name, &block) parent = owner.class.send(name) method = "#{name}_key" key = if owner.respond_to?(method) owner.send(method) else "#{owner.class.to_s.split('::').last.downcase}_#{owner.object_id}" end namespace = parent.namespace(name, key) namespace.define(&block) end def fetch_and_define_option(namespace, option_name) option = namespace.options.fetch(option_name) namespace.option(option.name, option.type_class, option.rules) option end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ns-options-0.1.1 | lib/ns-options/helper.rb |
ns-options-0.1.0 | lib/ns-options/helper.rb |