Class: ApiMaker::Ability
- Inherits:
-
Object
- Object
- ApiMaker::Ability
- Includes:
- CanCan::Ability
- Defined in:
- lib/api_maker/ability.rb
Instance Attribute Summary collapse
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
Instance Method Summary collapse
- #active_record?(subject) ⇒ Boolean
-
#can?(*args) ⇒ Boolean
Override methods from CanCan::Ability to first load abilities from the given resource.
-
#initialize(args: nil) ⇒ Ability
constructor
A new instance of Ability.
- #load_abilities(subject) ⇒ Object
- #model_adapter(*args) ⇒ Object
Constructor Details
#initialize(args: nil) ⇒ Ability
Returns a new instance of Ability.
6 7 8 9 |
# File 'lib/api_maker/ability.rb', line 6 def initialize(args: nil) @args = args @loader = ApiMaker::AbilityLoader.new(ability: self, args: args) end |
Instance Attribute Details
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
4 5 6 |
# File 'lib/api_maker/ability.rb', line 4 def loader @loader end |
Instance Method Details
#active_record?(subject) ⇒ Boolean
34 35 36 37 38 |
# File 'lib/api_maker/ability.rb', line 34 def active_record?(subject) return subject < ActiveRecord::Base if subject.class == Class subject.is_a?(ActiveRecord::Base) end |
#can?(*args) ⇒ Boolean
Override methods from CanCan::Ability to first load abilities from the given resource
12 13 14 15 16 |
# File 'lib/api_maker/ability.rb', line 12 def can?(*args) subject = args.second load_abilities(subject) super end |
#load_abilities(subject) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/api_maker/ability.rb', line 24 def load_abilities(subject) return unless active_record?(subject) if subject.class == Class loader.load_model_class(subject) elsif subject.class != Class loader.load_model_class(subject.class) end end |
#model_adapter(*args) ⇒ Object
18 19 20 21 22 |
# File 'lib/api_maker/ability.rb', line 18 def model_adapter(*args) subject = args.first load_abilities(subject) super end |