module Hashcraft::Dsl

The class API used to define options for a craftable class. Each class stores its own OptionSet instance along with materializing one for its inheritance chain (child has precedence.)

Attributes

local_key_transformer[R]
local_value_transformer[R]

Public Instance Methods

key_transformer(name) click to toggle source

DSL Method used to declare what the sub-class should use as a transformer for all keys. It will follow the typical inheritance chain and find the closest transformer to use (child-first).

# File lib/hashcraft/dsl.rb, line 23
def key_transformer(name)
  tap { @local_key_transformer = name }
end
option(*args) click to toggle source

The main class-level DSL method consumed by sub-classes. This is the entry-point for the declaration of available options.

# File lib/hashcraft/dsl.rb, line 58
    def option(*args)
      opts = args.last.is_a?(Hash) ? args.pop : {}

      args.each do |key|
        option = Option.new(key, opts)

        local_option_set.add(option)

        method_name = option.name

        class_eval <<~RUBY, __FILE__, __LINE__ + 1
          def #{method_name}(opts = {}, &block)
            option = find_option('#{method_name}')

            value!(option, opts, &block)
          end
        RUBY
      end

      self
    end
value_transformer(name) click to toggle source

DSL Method used to declare what the sub-class should use as a transformer for all values. It will follow the typical inheritance chain and find the closest transformer to use (child-first).

# File lib/hashcraft/dsl.rb, line 30
def value_transformer(name)
  tap { @local_value_transformer = name }
end