Sha256: 1e130ffd233fda8c6dfdd6d1381760e8df5e7341d2a125cdda2a906cc06dbccd

Contents?: true

Size: 530 Bytes

Versions: 1

Compression:

Stored size: 530 Bytes

Contents

# frozen_string_literal: true

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
key_mapable-0.6.0 lib/key_mapable.rb