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

Implement ScopeList and ResourceMap utilities #22

Merged
merged 8 commits into from
Apr 23, 2020
Merged

Conversation

cqr
Copy link
Contributor

@cqr cqr commented Apr 23, 2020

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.

@PRX PRX deleted a comment from coveralls Apr 23, 2020
@cqr cqr requested a review from cavis April 23, 2020 14:38
Copy link
Member

@cavis cavis left a 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
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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?

Copy link
Member

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!

end

describe '#-' do
it 'sutracts values' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*subtracts

@cavis cavis merged commit 73b9b20 into master Apr 23, 2020
@cavis cavis deleted the feat/condense branch April 23, 2020 18:08
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.

2 participants