Skip to content

ADStrovers/mint_condition

Repository files navigation

MintCondition

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.

Installation

Add this line to your application's Gemfile:

gem "mint_condition"

And then execute:

bundle install

Usage

Register 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"
end

Evaluate 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
# => 1000

You 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
end

Use MintCondition::Limits::UNLIMITED to represent no limits in a ruleset.

Development

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.

Contributing

Bug reports and pull requests are welcome. See CONTRIBUTING.md for details.

Security

Please report vulnerabilities privately. See SECURITY.md for details.

License

The gem is available as open source under the terms of the MIT License.

About

Mint Condition is a small ruby gem for helping enable entitlement based access

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors