Module: PaidUp::Ability

Includes:
CanCan::Ability
Defined in:
app/models/paid_up/ability.rb

Instance Method Summary collapse

Instance Method Details

#initialize_paid_up(user) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/paid_up/ability.rb', line 5

def initialize_paid_up(user)
  features = PaidUp::Feature.all

  for feature in features

    case feature.setting_type
      when 'table_rows'
        model = feature.name.classify.constantize
        if user.table_rows_allowed(feature.name) > 0 || user.table_rows_allowed(feature.name) == -1
          can :manage, model, :user => user
          can :own, model
          unless user.table_rows_remaining(feature.name) > 0
            cannot :create, model
          end
        end
        can :read, model
      when 'boolean'
        if user.plan.feature_setting feature.id
          can :use, feature.name.to_sym
        end
      else
        raise(:unknown_feature_type.l)
    end
  end
end