Skip to content

#361: Allow reading custom PMP properties from custom areas#505

Merged
yegor256 merged 2 commits into
zerocracy:masterfrom
VasilevNStas:fix/361-pmp-custom-props
Jun 13, 2026
Merged

#361: Allow reading custom PMP properties from custom areas#505
yegor256 merged 2 commits into
zerocracy:masterfrom
VasilevNStas:fix/361-pmp-custom-props

Conversation

@VasilevNStas

@VasilevNStas VasilevNStas commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Description

Fbe.pmp only allows accessing properties through areas defined in assets/pmp.xml. When a PMP fact has a custom area (not in the XML), accessing it via Fbe.pmp.custom_area.my_prop raises "Unknown area":

# This worked (area "hr" is in pmp.xml):
Fbe.pmp.hr.days_to_reward  # => 14 (from XML default)

# This raised (area "my_custom" is NOT in pmp.xml):
Fbe.pmp.my_custom.my_prop  # => "Unknown area 'my_custom'"

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:

f = fb.insert
f.what = 'pmp'
f.area = 'my_custom'
f.my_prop = 42
Fbe.pmp.my_custom.my_prop  # => 42 (now works)

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 area
  • test_custom_area_without_fact — verifies nil value when no fact exists
  • test_custom_area_properties — verifies properties method lists custom props

Verification

  • bundle exec rubocop — 0 offenses
  • bundle exec rake test — 285 tests, 0 failures

Closes #361

@VasilevNStas VasilevNStas force-pushed the fix/361-pmp-custom-props branch from 2ef3f3a to 2b47df1 Compare June 2, 2026 21:33

@edmoffo edmoffo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_area removes coverage of a previously-documented behaviour. The replacement is the right call now, but the docstring of Fbe.pmp still reads as if unknown areas are an error path. Update the YARD example around lib/fbe/pmp.rb:42 so callers know custom areas are supported and that returned pmpv carries nil for default, type, and memo outside the schema.
  • Inside the custom-area class, pmpv.new(result, nil, nil, nil) means .default, .type, and .memo are 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 kreinba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread lib/fbe/pmp.rb
if node.nil?
Class.new do
define_method(:properties) do
query.call(area).each.first&.all_properties&.map(&:to_s) || []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@VasilevNStas

Copy link
Copy Markdown
Contributor Author

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.
@VasilevNStas VasilevNStas force-pushed the fix/361-pmp-custom-props branch from 469a27c to 722c8be Compare June 3, 2026 19:26
@0crat

0crat commented Jun 4, 2026

Copy link
Copy Markdown

@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 VasilevNStas changed the title fix: allow reading custom PMP properties from custom areas #361 fix: allow reading custom PMP properties from custom areas Jun 8, 2026
@VasilevNStas VasilevNStas changed the title #361 fix: allow reading custom PMP properties from custom areas #361: Allow reading custom PMP properties from custom areas Jun 8, 2026
@yegor256 yegor256 merged commit e2e89cb into zerocracy:master Jun 13, 2026
10 checks passed
@0crat

0crat commented Jun 13, 2026

Copy link
Copy Markdown

@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.

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.pmp can't read custom properties

5 participants