feat: Add cohort evaluation support for local feature flag evaluation#74
Merged
feat: Add cohort evaluation support for local feature flag evaluation#74
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements comprehensive cohort evaluation support for local feature flag evaluation in the Ruby SDK, bringing it to feature parity with other server-side SDKs (Python, Node.js, Go, PHP, .NET). The implementation enables full local evaluation of feature flags that depend on cohorts, eliminating the need for additional API calls and improving performance.
- Adds
send_cohortsparameter to local evaluation requests to retrieve cohort definitions - Implements
match_cohort()andmatch_property_group()methods for evaluating complex nested cohort logic - Updates the feature flag evaluation chain to support cohort properties alongside regular properties
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/posthog/feature_flags.rb | Core implementation of cohort evaluation logic with nested property group support |
| spec/posthog/flags_spec.rb | Comprehensive test coverage for cohort evaluation scenarios including edge cases |
| spec/posthog/feature_flag_spec.rb | Updates test stubs to include new send_cohorts=true parameter |
| spec/posthog/client_spec.rb | Updates test stubs to match new URL format with cohort parameter |
| example.rb | Enhanced demo script with interactive menu and complex cohort examples |
| EXAMPLE_SETUP.md | Documentation for setting up the example script with cohort configurations |
| .env.example | Environment configuration template for the example script |
Implements comprehensive cohort evaluation to enable full local evaluation of feature flags that depend on cohorts, bringing the Ruby SDK to feature parity with other server-side SDKs (Python, Node.js, Go, PHP, .NET). Key changes: - Add `send_cohorts` parameter to local evaluation requests - Implement cohort storage and management in FeatureFlagsPoller - Add `match_cohort()` and `match_property_group()` methods for cohort evaluation - Support nested property groups with AND/OR logic - Handle cohort-type properties in match_property() - Update flag evaluation chain to pass cohort properties - Add comprehensive test coverage for all cohort scenarios - Update all test stubs to expect new URL format This enables local evaluation of flags with cohorts, reducing API calls and improving performance while maintaining backward compatibility. Fixes #73
594f41b to
25258b7
Compare
c1f0807 to
bec6ddd
Compare
Ran bin/fmt. Had to manually fix some.
cb28927 to
47cdee0
Compare
andyzzhao
reviewed
Aug 11, 2025
| POSTHOG_PERSONAL_API_KEY=phx_your_personal_key_here | ||
|
|
||
| # PostHog host URL | ||
| POSTHOG_HOST=https://app.posthog.com # or your self-hosted URL |
Contributor
There was a problem hiding this comment.
shouldn't this be us.posthog.com or eu.posthog.com?
andyzzhao
reviewed
Aug 11, 2025
andyzzhao
reviewed
Aug 11, 2025
- Change default from app.posthog.com to us.posthog.com in examples - Add eu.posthog.com option in comments for EU users - Update both .env.example and EXAMPLE_SETUP.md
andyzzhao
approved these changes
Aug 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements comprehensive cohort evaluation to enable full local evaluation of feature flags that depend on cohorts, bringing the Ruby SDK to feature parity with other server-side SDKs (Python, Node.js, Go, PHP, .NET).
Key changes:
send_cohortsparameter to local evaluation requestsmatch_cohort()andmatch_property_group()methods for cohort evaluationThis enables local evaluation of flags with cohorts, reducing API calls and improving performance while maintaining backward compatibility.
Fixes #73