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

Allow given? to check array filters #476

Closed
mattgmarcus opened this issue Dec 3, 2019 · 1 comment
Closed

Allow given? to check array filters #476

mattgmarcus opened this issue Dec 3, 2019 · 1 comment
Assignees

Comments

@mattgmarcus
Copy link

Currently, the given? method can only check values on top-level filters or hash filters.

def given?(input, *rest) # rubocop:disable Metrics/CyclomaticComplexity
filter_level = self.class
input_level = @_interaction_inputs
[input, *rest].map(&:to_sym).each do |key|
filter_level = filter_level.filters[key]
break false if filter_level.nil? || input_level.nil?
break false unless input_level.key?(key) || input_level.key?(key.to_s)
input_level = input_level[key] || input_level[key.to_s]
end && true
end

Given a set of filters like this

array :line_items do
  hash do
    integer :amount
    string :description, default: nil
  end
end

I would love to be able to do something like

given?(:line_items, 0, :description)

I've hacked together a rudimentary version of this for now

def given_line_item_field?(index, field)
  @_interaction_inputs.dig(:line_items, index).key?(field)
end
@mattgmarcus
Copy link
Author

Thanks for fixing @AaronLasseigne!

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

No branches or pull requests

2 participants