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
-
#description(*args) ⇒ Object
Sets or returns the description of this plan When called without arguments, it returns the description When called with arguments, the description is set to the first argument provided.
-
#disable_feature(feature_name) ⇒ Object
Disables a feature on this plan.
-
#dup ⇒ Planify::Plan
Returns a duplicate instance of this plan.
-
#enable_feature(feature_name) ⇒ Object
Enables a feature on this plan.
-
#feature(feature_name, enabled = true) ⇒ Object
Defines a feature of this plan.
-
#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::Limitable
that a user can create on this plan. -
#merge!(other_plan) ⇒ nil
Merges limits and features from
other_plan
into self. -
#name(*args) ⇒ Object
Sets or returns the name of this plan When called without arguments, it returns the name When called with arguments, the name is set to the first argument provided.
-
#price(*args) ⇒ Object
Sets or returns the price of this plan.
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
#description(*args) ⇒ Object
Sets or returns the description of this plan When called without arguments, it returns the description When called with arguments, the description is set to the first argument provided.
85 86 87 88 89 90 91 |
# File 'lib/planify/plan.rb', line 85 def description(*args) unless args.empty? @description = args.first end @description ||= nil end |
#disable_feature(feature_name) ⇒ Object
Disables a feature on this plan.
42 43 44 |
# File 'lib/planify/plan.rb', line 42 def disable_feature(feature_name) feature(feature_name, false) end |
#dup ⇒ Planify::Plan
Returns a duplicate instance of this plan
95 96 97 98 99 100 |
# File 'lib/planify/plan.rb', line 95 def dup duplicate = Plan.new duplicate.merge! self duplicate end |
#enable_feature(feature_name) ⇒ Object
Enables a feature on this plan.
36 37 38 |
# File 'lib/planify/plan.rb', line 36 def enable_feature(feature_name) feature(feature_name, true) end |
#feature(feature_name, enabled = true) ⇒ Object
Defines a feature of this plan
30 31 32 |
# File 'lib/planify/plan.rb', line 30 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
56 57 58 |
# File 'lib/planify/plan.rb', line 56 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
49 50 51 |
# File 'lib/planify/plan.rb', line 49 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.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/planify/plan.rb', line 105 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 name other_plan.name description other_plan.description price other_plan.price nil end |
#name(*args) ⇒ Object
Sets or returns the name of this plan When called without arguments, it returns the name When called with arguments, the name is set to the first argument provided
74 75 76 77 78 79 80 |
# File 'lib/planify/plan.rb', line 74 def name(*args) unless args.empty? @name = args.first end @name ||= nil end |
#price(*args) ⇒ Object
Sets or returns the price of this plan. When called without arguments, it returns the price. When called with arguments, the price is set to the first argument provided.
63 64 65 66 67 68 69 |
# File 'lib/planify/plan.rb', line 63 def price(*args) unless args.empty? @price = args.first end @price ||= 0.00 end |