Class: ApiMaker::AbilityLoader
- Inherits:
-
Object
- Object
- ApiMaker::AbilityLoader
- Defined in:
- lib/api_maker/ability_loader.rb
Instance Attribute Summary collapse
-
#ability ⇒ Object
readonly
Returns the value of attribute ability.
-
#api_maker_args ⇒ Object
readonly
Returns the value of attribute api_maker_args.
-
#loaded ⇒ Object
readonly
Returns the value of attribute loaded.
-
#loaded_model_names ⇒ Object
readonly
Returns the value of attribute loaded_model_names.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
Instance Method Summary collapse
-
#initialize(ability:, api_maker_args:, locals:) ⇒ AbilityLoader
constructor
A new instance of AbilityLoader.
- #load_model_class(model_class) ⇒ Object
- #load_resource(resource) ⇒ Object
Constructor Details
#initialize(ability:, api_maker_args:, locals:) ⇒ AbilityLoader
Returns a new instance of AbilityLoader.
4 5 6 7 8 9 |
# File 'lib/api_maker/ability_loader.rb', line 4 def initialize(ability:, api_maker_args:, locals:) @ability = ability @api_maker_args = api_maker_args @locals = locals @loaded_model_names = {} end |
Instance Attribute Details
#ability ⇒ Object (readonly)
Returns the value of attribute ability.
2 3 4 |
# File 'lib/api_maker/ability_loader.rb', line 2 def ability @ability end |
#api_maker_args ⇒ Object (readonly)
Returns the value of attribute api_maker_args.
2 3 4 |
# File 'lib/api_maker/ability_loader.rb', line 2 def api_maker_args @api_maker_args end |
#loaded ⇒ Object (readonly)
Returns the value of attribute loaded.
2 3 4 |
# File 'lib/api_maker/ability_loader.rb', line 2 def loaded @loaded end |
#loaded_model_names ⇒ Object (readonly)
Returns the value of attribute loaded_model_names.
2 3 4 |
# File 'lib/api_maker/ability_loader.rb', line 2 def loaded_model_names @loaded_model_names end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
2 3 4 |
# File 'lib/api_maker/ability_loader.rb', line 2 def locals @locals end |
Instance Method Details
#load_model_class(model_class) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/api_maker/ability_loader.rb', line 11 def load_model_class(model_class) return if loaded_model_names.key?(model_class.name) resource = ApiMaker::MemoryStorage.current.resource_for_model(model_class) load_resource(resource) end |
#load_resource(resource) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/api_maker/ability_loader.rb', line 18 def load_resource(resource) return if loaded_model_names.key?(resource.model_class_name) resource.new(ability: ability, api_maker_args: api_maker_args, locals: locals, model: nil).abilities loaded_model_names[resource.model_class_name] = true end |