-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement ScopeList and ResourceMap utilities #22
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 These all make sense to me.
end | ||
end | ||
|
||
if tripped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just avoiding the overhead of instantiating a new object when nothing changed?
def &(other_list) | ||
return ScopeList.new('') if other_list.nil? | ||
|
||
self - (self - other_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to think about this for a second ... but it works!
it 'adds values' do | ||
map = new_map("one" => "two", "two" => "four") + new_map("one" => "three", "three" => "six") | ||
assert map.contains?('one', :two) && map.contains?('one', :three) | ||
assert map.contains?('two', :four) && map.contains?('three', :six) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 2 assertions on 1 line here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I find the &&
assertions a bit strange. But I guess the alternative is a whole bunch more lines. So I'm going to learn to live with it!
test/prx_auth/resource_map_test.rb
Outdated
end | ||
|
||
describe '#-' do | ||
it 'sutracts values' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*subtracts
I found myself needing some basic arithmetic (mostly, the intersect
&
operator) in id and started to implement there but thought it was better to do so here. Because of wildcard semantics it wound up being a little more complicated than it seems like it should be - especially ResourceMap#&Luckily, because we don't have any way to do expansion in either case this can be mathematically correct. Subtracting non-wildcard values from a wildcard does mean that subtraction is not always technically complete, but this works fine for our purposes.