Fix code climate issues on Plan model (#98)

This commit is contained in:
Jaques Dias
2019-10-02 15:46:32 +02:00
committed by Pranav Raj S
parent d1f06992b2
commit 9afbc8c55f

View File

@@ -27,7 +27,6 @@ class Plan
end end
class << self class << self
def config def config
Hashie::Mash.new(PLAN_CONFIG) Hashie::Mash.new(PLAN_CONFIG)
end end
@@ -41,7 +40,7 @@ class Plan
end end
def default_plans def default_plans
load_plans_from_config load_active_plans + load_inactive_plans
end end
def all_plans def all_plans
@@ -49,7 +48,7 @@ class Plan
end end
def active_plans def active_plans
all_plans.select{|plan| plan.active } all_plans.select { |plan| plan.active }
end end
def paid_plan def paid_plan
@@ -57,44 +56,29 @@ class Plan
end end
def inactive_plans def inactive_plans
all_plans.reject{|plan| plan.active } all_plans.reject(&:active)
end end
def trial_plan def trial_plan
all_plans.select{|plan| plan.key == :trial}.first all_plans.select { |plan| plan.key == :trial }.first
end end
def plans_of_version(version) def plans_of_version(version)
all_plans.select{|plan| plan.version == version} all_plans.select { |plan| plan.version == version }
end end
def find_by_key(key) def find_by_key(key)
key = key.to_sym key = key.to_sym
all_plans.select{|plan| plan.key == key}.first.dup all_plans.select { |plan| plan.key == key }.first.dup
end
def get_plan_of_account(account)
# subscription = account.subscription
# plan = find_by_key(account.billing_plan)
end
def get_active_plans_for_account(account)
# subscription = account.subscription
# version = subscription.pricing_version
# return plans_of_version(version) + [trial_plan]
end end
##helpers ##helpers
def load_plans_from_config
load_active_plans + load_inactive_plans
end
def load_active_plans def load_active_plans
result = [] result = []
Plan.config.active.each_pair do |version, plans| Plan.config.active.each_pair do |version, plans|
plans.each_pair do |key, attributes| plans.each_pair do |key, attributes|
result << Plan.new(key, attributes.merge({active: true, version: version})) result << Plan.new(key, attributes.merge(active: true, version: version))
end end
end end
result result
@@ -104,7 +88,7 @@ class Plan
result = [] result = []
Plan.config.inactive.each_pair do |version, plans| Plan.config.inactive.each_pair do |version, plans|
plans.each_pair do |key, attributes| plans.each_pair do |key, attributes|
result << Plan.new(key, attributes.merge({active: false, version: version})) result << Plan.new(key, attributes.merge(active: false, version: version))
end end
end end
result result