#361: Allow reading custom PMP properties from custom areas#505
Conversation
2ef3f3a to
2b47df1
Compare
edmoffo
left a comment
There was a problem hiding this comment.
The fallback in the new node.nil? branch closes #361 — custom areas now route to the factbase via the captured query lambda — and the three new tests pin down the value, the missing-fact, and the properties listings. Logic is reasonable. CI is green.
Notes:
- Removing
test_fail_on_wrong_arearemoves coverage of a previously-documented behaviour. The replacement is the right call now, but the docstring ofFbe.pmpstill reads as if unknown areas are an error path. Update the YARD example aroundlib/fbe/pmp.rb:42so callers know custom areas are supported and that returnedpmpvcarriesnilfordefault,type, andmemooutside the schema. - Inside the custom-area class,
pmpv.new(result, nil, nil, nil)means.default,.type, and.memoare nil. If any existing call site invokes those accessors it will silently lose information. Worth a one-line note in the README or method doc. - This branch conflicts with #498 on
lib/fbe/pmp.rb:95. Coordinate the merge order with #498's author.
Drop the unrelated downgrade of crate-ci/typos in .github/workflows/typos.yml.
kreinba
left a comment
There was a problem hiding this comment.
The split between known-area (with XML defaults and type coercion) and unknown-area (direct factbase read) is the right shape for issue #361, and the query lambda neatly removes the duplicated Fbe.fb chain at lines 58 and 73 of the old code. One inline note about properties returning internal columns.
| if node.nil? | ||
| Class.new do | ||
| define_method(:properties) do | ||
| query.call(area).each.first&.all_properties&.map(&:to_s) || [] |
There was a problem hiding this comment.
all_properties on a pmp fact also returns the bookkeeping columns (_id, _time, what, area), so .custom.properties will list those alongside the real PMP properties. The XML branch limits the list to entries under
. Filtering out what, area, and any leading underscore name would keep parity with the XML branch. test_custom_area_properties uses assert_includes which masks the extra entries.
|
YARD doc updated with notes about custom areas and nil default/type/memo. @edmoffo |
Fbe.pmp only allowed accessing PMP properties through areas defined in pmp.xml. Any PMP fact with a custom area (not in pmp.xml) would raise 'Unknown area' when accessed via Fbe.pmp.custom_area.prop. Now when an area is not found in pmp.xml, a fallback handler is created that reads properties directly from the factbase without XML defaults or type coercion. Also refactored the duplicated query into a local lambda to reduce code duplication.
469a27c to
722c8be
Compare
|
@kreinba Hey! Nice work on that review 👍 You snagged +13 points this time: started with the standard +18 base, but lost -5 for having just 1 comment (our policy dings us when there's fewer than 9 comments). Your running total is now +1498 - keep crushing it! Don't forget to peek at your Zerocracy account when you get a chance. |
|
@VasilevNStas Thanks for the contribution! You've earned +16 points for this: +24 as a basis; +9.3 for the 124 hits-of-code that you wrote; -8 for no code review; -9.3 to not exceed the maximum cap of 24 points. Please, keep them coming. Your running score is +1574; don't forget to check your Zerocracy account too. |
Description
Fbe.pmponly allows accessing properties through areas defined inassets/pmp.xml. When a PMP fact has a custom area (not in the XML), accessing it viaFbe.pmp.custom_area.my_propraises "Unknown area":Fix
When an area is not found in
pmp.xml, fall back to reading properties directly from the factbase without XML defaults or type coercion. This allows custom PMP properties to be accessed:Built-in areas with XML definitions continue to work as before with defaults and type coercion.
Tests
test_custom_area— verifies custom property is readable via custom areatest_custom_area_without_fact— verifies nil value when no fact existstest_custom_area_properties— verifiespropertiesmethod lists custom propsVerification
bundle exec rubocop— 0 offensesbundle exec rake test— 285 tests, 0 failuresCloses #361