Class: GrapeSwagger::Entity::Helper
- Inherits:
-
Object
- Object
- GrapeSwagger::Entity::Helper
- Defined in:
- lib/grape-swagger/entity/helper.rb
Overview
Helper methods for DRY
Class Method Summary collapse
- .discriminator(entity_model) ⇒ Object
- .model_name(entity_model, endpoint) ⇒ Object
- .root_exposure_with_discriminator(entity_model) ⇒ Object
- .root_exposures_without_parent(entity_model) ⇒ Object
Class Method Details
.discriminator(entity_model) ⇒ Object
16 17 18 19 20 |
# File 'lib/grape-swagger/entity/helper.rb', line 16 def discriminator(entity_model) entity_model.superclass.root_exposures.detect do |value| value.documentation&.dig(:is_discriminator) end end |
.model_name(entity_model, endpoint) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/grape-swagger/entity/helper.rb', line 8 def model_name(entity_model, endpoint) if endpoint.nil? entity_model.to_s.demodulize else endpoint.send(:expose_params_from_model, entity_model) end end |
.root_exposure_with_discriminator(entity_model) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/grape-swagger/entity/helper.rb', line 28 def root_exposure_with_discriminator(entity_model) if discriminator(entity_model) root_exposures_without_parent(entity_model) else entity_model.root_exposures end end |
.root_exposures_without_parent(entity_model) ⇒ Object
22 23 24 25 26 |
# File 'lib/grape-swagger/entity/helper.rb', line 22 def root_exposures_without_parent(entity_model) entity_model.root_exposures.select do |value| entity_model.superclass.root_exposures.find_by(value.attribute).nil? end end |