Skip to content

Refuse a second assignment to the same property in Fbe.if_absent and Fbe.just_one - #1330

Open
Thayorns wants to merge 1 commit into
zerocracy:masterfrom
Thayorns:1244
Open

Thayorns wants to merge 1 commit into
zerocracy:masterfrom
Thayorns:1244

Conversation

@Thayorns

Copy link
Copy Markdown
Contributor

The object that Fbe.if_absent and Fbe.just_one pass to their block kept the values in a Hash, so assigning the same property twice silently dropped the first value. A real fact would keep both, and both helpers already refuse an Array because they match by one value per property.

A second assignment to a property now raises Fbe::Error, naming the property, the new value and the one it already has, and nothing is inserted. The tests cover both the error and the empty factbase afterwards, for each helper.

To keep the complexity of both methods where it was, the empty string check next to the new line is written as v == '' instead of v.is_a?(String) && v.empty?. It means the same and has one branch less. The perceived complexity of if_absent is still 17 of 15, exactly as on master; this change does not touch that.

Closes #1244

@Thayorns

Copy link
Copy Markdown
Contributor Author

@yegor256 take a look please, happy to clarify anything about the change.

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.

Fbe.if_absent and Fbe.just_one keep only the last value when the block assigns a property twice

1 participant