Class: Planify::Plan
- Inherits:
-
Object
- Object
- Planify::Plan
- Defined in:
- lib/planify/plan.rb
Overview
The Planify::Plan class provides functionality for storing class creation limits and available features. It also embodies a simple DSL for defining these attributes.
Instance Attribute Summary collapse
-
#features ⇒ Object
readonly
Returns the value of attribute features.
-
#limits ⇒ Object
readonly
Returns the value of attribute limits.
Instance Method Summary collapse
-
#dup ⇒ Planify::Plan
Returns a duplicate instance of this plan.
- #feature(feature_name, enabled = true) ⇒ Object
-
#feature_disabled?(feature) ⇒ Boolean
Boolean method for determining if a certain feature is disabled in this plan.
-
#feature_enabled?(feature) ⇒ Boolean
Boolean method for determining if a certain feature is enabled in this plan.
-
#initialize(limits = {}, features = {}) ⇒ Plan
constructor
A new instance of Plan.
-
#limit(limitable) ⇒ Integer, Float::INFINITY
Gets the plan’s limit for a given class constant.
-
#max(limitable, limit) ⇒ Object
Sets the maximum number of a
Planify::Limitablethat a user can create on this plan. -
#merge!(other_plan) ⇒ nil
Merges limits and features from
other_planinto self.
Constructor Details
#initialize(limits = {}, features = {}) ⇒ Plan
Returns a new instance of Plan.
8 9 10 11 |
# File 'lib/planify/plan.rb', line 8 def initialize(limits = {}, features = {}) @limits = Limitations.new(limits) @features = features end |
Instance Attribute Details
#features ⇒ Object (readonly)
Returns the value of attribute features.
6 7 8 |
# File 'lib/planify/plan.rb', line 6 def features @features end |
#limits ⇒ Object (readonly)
Returns the value of attribute limits.
6 7 8 |
# File 'lib/planify/plan.rb', line 6 def limits @limits end |
Instance Method Details
#dup ⇒ Planify::Plan
Returns a duplicate instance of this plan
47 48 49 50 51 52 |
# File 'lib/planify/plan.rb', line 47 def dup duplicate = Plan.new duplicate.merge! self duplicate end |
#feature(feature_name, enabled = true) ⇒ Object
27 28 29 |
# File 'lib/planify/plan.rb', line 27 def feature(feature_name, enabled = true) @features[feature_name.to_sym] = enabled end |
#feature_disabled?(feature) ⇒ Boolean
Boolean method for determining if a certain feature is disabled in this plan
41 42 43 |
# File 'lib/planify/plan.rb', line 41 def feature_disabled?(feature) !feature_enabled?(feature) end |
#feature_enabled?(feature) ⇒ Boolean
Boolean method for determining if a certain feature is enabled in this plan
34 35 36 |
# File 'lib/planify/plan.rb', line 34 def feature_enabled?(feature) @features[feature.to_sym] || false end |
#limit(limitable) ⇒ Integer, Float::INFINITY
Gets the plan’s limit for a given class constant
23 24 25 |
# File 'lib/planify/plan.rb', line 23 def limit(limitable) @limits.get(limitable) end |
#max(limitable, limit) ⇒ Object
Sets the maximum number of a Planify::Limitable that a user can create on this plan
16 17 18 |
# File 'lib/planify/plan.rb', line 16 def max(limitable, limit) @limits.set(limitable, limit) end |
#merge!(other_plan) ⇒ nil
Merges limits and features from other_plan into self.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/planify/plan.rb', line 57 def merge!(other_plan) other_plan.features.each do |f, enabled| feature f, enabled end other_plan.limits.all.each do |klass, lim| max klass, lim end nil end |