MintCondition is a lightweight, framework-agnostic entitlements engine. It lets you define capabilities, evaluate plan rules, and return structured decisions (booleans and limits) without tying your app to any specific billing or authorization system.
Add this line to your application's Gemfile:
gem "mint_condition"And then execute:
bundle installRegister capabilities:
MintCondition::Capabilities.register(
"messages.send",
"messages.max",
"reports.export"
)Define a ruleset (per plan or tier):
ruleset = MintCondition::Ruleset.build do
allow "messages.send"
limit "messages.max", 1000
deny "reports.export"
endEvaluate entitlements:
checker = MintCondition::Checker.new(ruleset: ruleset, context: { plan: "pro" })
checker.allowed?("messages.send")
# => true
decision = checker.allow("messages.max")
decision.allowed?
# => true
decision.value
# => 1000You can also use the module-level helpers:
MintCondition.allowed?("messages.send", ruleset: ruleset)Configure unknown capability behavior and instrumentation:
MintCondition.configure do |config|
config.unknown_capability = :allow # :deny or :raise
config.instrumenter = lambda do |event, payload|
# hook into your logger or tracer
end
endUse MintCondition::Limits::UNLIMITED to represent no limits in a ruleset.
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome. See CONTRIBUTING.md for details.
Please report vulnerabilities privately. See SECURITY.md for details.
The gem is available as open source under the terms of the MIT License.