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

Support nested dependent parameters #1811

Merged
merged 2 commits into from
Nov 1, 2018

Conversation

darren987469
Copy link
Contributor

@darren987469 darren987469 commented Nov 1, 2018

Fixes #1800. Continue of #1804.

given will check whether attribute is declared in its scope.
If not, it raises an error.

optional :a
given a: ->(val) { val == 'a' } do
  optional :b
  given b: ->(val) { val == 'b' } do
    requires :c
  end
end

In the example, optional :a creates a scope. given a: ... creates
another scope
, which parent scope is the one created by optional :a,
and attributes :b declared in optional :b is pushed to parent scope.

The bug here is given b: ... cannot find :b in its scope. Since the
attribute :b is pushed to its parent scope. So, fix the code to
check attribute in its parent scope if it has parent scope.

andreacfm and others added 2 commits November 1, 2018 08:55
`given` will check whether attribute is declared in its scope.
If not, it raises an error.

```ruby
optional :a
given a: ->(val) { val == 'a' } do
  optional :b
  given b: ->(val) { val == 'b' } do
    requires :c
  end
end
```

In the example, `optional :a` creates a scope. `given a: ...` creates
another scope, which parent scope is the one created by `optional :a`,
and attributes `:b` declared in `optional :b` is pushed to parent scope.

The bug here is `given b: ...` cannot find `:b` in its scope. Since the
attribute `:b` is pushed to its parent scope. So, fix the code to
check attribute in its parent scope if it has parent scope.
@dblock
Copy link
Member

dblock commented Nov 1, 2018

🚀 thanks!

@dblock dblock merged commit f4eb30c into ruby-grape:master Nov 1, 2018
@darren987469 darren987469 deleted the fix_issue_1800 branch November 1, 2018 15:09
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

Successfully merging this pull request may close these issues.

Unsupported nested given blocks
3 participants