Sha256: 6834391b6df55dae834ff0e75a335e31f2209046e9c7b3c89274d747feebd1aa

Contents?: true

Size: 383 Bytes

Versions: 3

Compression:

Stored size: 383 Bytes

Contents

# frozen_string_literal: true

require "key_mapable/version"
require "key_mapable/mapper"

module KeyMapable
  def define_map(method_name, resolve: ->(val) { val }, subject: :itself, &block)
    define_method(method_name) do
      value = public_send(subject)
      mapper = Mapper.new(value)
      mapper.instance_eval(&block)
      resolve.call(mapper.structure)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
key_mapable-0.5.0 lib/key_mapable.rb
key_mapable-0.4.0 lib/key_mapable.rb
key_mapable-0.3.0 lib/key_mapable.rb