Class: SaasPlatform::PlanService
- Inherits:
-
Object
- Object
- SaasPlatform::PlanService
- Defined in:
- app/services/saas_platform/plan_service.rb
Constant Summary collapse
- PLANS =
{ 'free' => { name: 'Free', max_users: 2, max_products: 5, features: [:basic_analytics] }, 'pro' => { name: 'Pro', max_users: 10, max_products: 100, features: [:basic_analytics, :advanced_analytics, :api_access] }, 'enterprise' => { name: 'Enterprise', max_users: 1000, max_products: 10000, features: [:basic_analytics, :advanced_analytics, :api_access, :webhooks, :audit_logs] } }.freeze
Instance Method Summary collapse
- #can_add_product? ⇒ Boolean
- #can_add_user? ⇒ Boolean
- #has_feature?(feature) ⇒ Boolean
-
#initialize(account) ⇒ PlanService
constructor
A new instance of PlanService.
- #plan_details ⇒ Object
Constructor Details
#initialize(account) ⇒ PlanService
Returns a new instance of PlanService.
24 25 26 27 |
# File 'app/services/saas_platform/plan_service.rb', line 24 def initialize(account) @account = account @plan_config = PLANS[account.plan_name] || PLANS['free'] end |
Instance Method Details
#can_add_product? ⇒ Boolean
33 34 35 |
# File 'app/services/saas_platform/plan_service.rb', line 33 def can_add_product? @account.products.count < @plan_config[:max_products] end |
#can_add_user? ⇒ Boolean
29 30 31 |
# File 'app/services/saas_platform/plan_service.rb', line 29 def can_add_user? @account.users.count < @plan_config[:max_users] end |
#has_feature?(feature) ⇒ Boolean
37 38 39 |
# File 'app/services/saas_platform/plan_service.rb', line 37 def has_feature?(feature) @plan_config[:features].include?(feature.to_sym) end |
#plan_details ⇒ Object
41 42 43 |
# File 'app/services/saas_platform/plan_service.rb', line 41 def plan_details @plan_config end |