Created
May 22, 2020 08:33
-
-
Save slim1979/6b029b10cad640aea843dc5dd08564d2 to your computer and use it in GitHub Desktop.
expected structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User | |
| enum tariff: %i[free standart unlimited] | |
| end | |
| class Album < ApplicationRecord | |
| extend tariff | |
| def self.tariff | |
| user.tariff.camelize.constantize | |
| end | |
| module Free | |
| extend News | |
| extend Blog | |
| extend SomeThingFree | |
| end | |
| module Standard | |
| # standard modules | |
| end | |
| module Unlimited | |
| # unlimited modules | |
| end | |
| end | |
| # models, controllers | |
| class AlbumsController < ApplicationController | |
| extend current_user.tariff.camelize.constantize | |
| end | |
| # concern | |
| class AlbumsController | |
| module Free | |
| extend News | |
| extend Blog | |
| extend SomeThingFree | |
| end | |
| module Standard | |
| # standard modules | |
| end | |
| module Unlimited | |
| # unlimited modules | |
| end | |
| end | |
| class Ability | |
| include CanCan::Ability | |
| def case_user_tariff | |
| send @user.tariff + '_abilities' | |
| rescue NoMethodError => e | |
| puts e | |
| end | |
| def free_abilities | |
| end | |
| def standard_abilities | |
| end | |
| def custom_abilities | |
| @user.custom_tariff.keys do |k| | |
| can :manage, k.to_s.camelize.constantize, @user.custom_tariff[k] == true | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment