Module: Planify::User
- Includes:
- ClassHelper
- Defined in:
- lib/planify/user.rb,
lib/planify/user/plan_info.rb,
lib/planify/user/limitable_counts.rb
Defined Under Namespace
Classes: LimitableCounts, PlanInfo
Class Method Summary
collapse
Instance Method Summary
collapse
#normalize_class
Class Method Details
.included(base) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/planify/user.rb', line 10
def self.included(base)
base.class_eval do
embeds_one :planify_plan_info, as: :planify_user, class_name: "Planify::User::PlanInfo", validate: false
embeds_one :planify_limitable_counts, as: :planify_user, class_name: "Planify::User::LimitableCounts", validate: false
end
end
|
Instance Method Details
#can_create?(limitable) ⇒ Boolean
59
60
61
62
|
# File 'lib/planify/user.rb', line 59
def can_create?(limitable)
key = normalize_class(limitable)
limitable_counts.fetch(key) < plan.limit(key)
end
|
#created(limitable) ⇒ Object
49
50
51
52
|
# File 'lib/planify/user.rb', line 49
def created(limitable)
key = normalize_class(limitable)
limitable_counts.increment(key)
end
|
#creation_count(limitable) ⇒ Object
44
45
46
47
|
# File 'lib/planify/user.rb', line 44
def creation_count(limitable)
key = normalize_class(limitable)
limitable_counts.fetch(key)
end
|
#destroyed(limitable) ⇒ Object
54
55
56
57
|
# File 'lib/planify/user.rb', line 54
def destroyed(limitable)
key = normalize_class(limitable)
limitable_counts.decrement(key)
end
|
#has_feature?(feature) ⇒ Boolean
64
65
66
|
# File 'lib/planify/user.rb', line 64
def has_feature?(feature)
plan.feature_enabled?(feature)
end
|
#has_plan(plan_name, &block) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/planify/user.rb', line 17
def has_plan(plan_name, &block)
plan = Planify::Plans.get(plan_name)
plan_info = PlanInfo.new(name: plan_name)
if block_given?
plan = plan.dup
configuration = Planify::Plan.new
configuration.instance_eval &block
plan.merge! configuration
plan_info.limit_overrides = configuration.limits.all
plan_info.feature_overrides = configuration.features
end
self.planify_plan_info = plan_info
nil
end
|
#limitable_counts ⇒ Object
40
41
42
|
# File 'lib/planify/user.rb', line 40
def limitable_counts
self.planify_limitable_counts ||= LimitableCounts.new
end
|
#plan ⇒ Object
36
37
38
|
# File 'lib/planify/user.rb', line 36
def plan
@plan ||= load_plan_from_info(self.planify_plan_info)
end
|