Sha256: fd452de31e1cf237864a6e1fbed1b401ed6835a9d8f3de4ef834655dfcd19432

Contents?: true

Size: 962 Bytes

Versions: 9

Compression:

Stored size: 962 Bytes

Contents

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new # anonymous user (not logged in)

    # Rails Application's initialization could go here.

    initialize_paid_up(user)
  end

  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
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
paid_up-0.1.9 app/models/ability.rb
paid_up-0.1.8 app/models/ability.rb
paid_up-0.1.7 app/models/ability.rb
paid_up-0.1.6 app/models/ability.rb
paid_up-0.1.5 app/models/ability.rb
paid_up-0.1.4 app/models/ability.rb
paid_up-0.1.3 app/models/ability.rb
paid_up-0.1.1 app/models/ability.rb
paid_up-0.1.0 app/models/ability.rb