lib/key_mapable.rb in key_mapable-0.5.0 vs lib/key_mapable.rb in key_mapable-0.6.0
- old
+ new
@@ -1,14 +1,19 @@
# 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, &block)
+ def define_map(method_name,
+ resolve: ->(val) { val },
+ subject: :itself,
+ access: :method, &block)
define_method(method_name) do
value = public_send(subject)
- mapper = Mapper.new(value)
+ accessor = Accessor.for(access)
+ mapper = Mapper.new(value, accessor)
mapper.instance_eval(&block)
resolve.call(mapper.structure)
end
end
end