Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Having a contract refer to previous values #53

Open
badBlackShark opened this issue Feb 24, 2023 · 0 comments
Open

Question: Having a contract refer to previous values #53

badBlackShark opened this issue Feb 24, 2023 · 0 comments

Comments

@badBlackShark
Copy link

I have a very particular case, where I have a set of mappers (where only one should apply), the selection of which depends on a value earlier in the path. Here an example that I hope is not too convoluted:

class Embedded < Remap::Base
  contract do
    # Check somehow that `values.get(:d)` is true
  end

  define do
    map(:b, to: :test)
    to(:static).then { 'd is true' }
  end
end

class Test < Remap::Base
  define do
    map [:a] do
      each do
        map(:c, to: :something)
        embed Embedded
      end
    end
  end
end

Test.call({ a: [{ b: 1, c: 2 }, { b: 3, c: 4 }], d: true })

Is there a way to reference not the input of the mapper, but what came before it in the contract?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant