Class: PetstoreApiClient::Models::Base
- Inherits:
-
Object
- Object
- PetstoreApiClient::Models::Base
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Serialization, ActiveModel::Validations
- Defined in:
- lib/petstore_api_client/models/base.rb
Overview
Base class for all API models Provides common ActiveModel functionality and shared behavior
This follows the DRY principle by centralizing all the common ActiveModel includes that every model needs.
Benefits:
-
Single place to add model-wide functionality
-
Consistent behavior across all models
-
Reduces boilerplate in model classes
Direct Known Subclasses
Class Method Summary collapse
-
.from_response(data) ⇒ Base?
Create model instance from API response data This is a template method - subclasses must implement their own field mapping logic since each model has different fields.
Instance Method Summary collapse
-
#to_h ⇒ Object
Convert model to hash for API requests Subclasses can override this for custom serialization Default implementation uses compact to remove nil values.
Class Method Details
.from_response(data) ⇒ Base?
Create model instance from API response data This is a template method - subclasses must implement their own field mapping logic since each model has different fields
34 35 36 |
# File 'lib/petstore_api_client/models/base.rb', line 34 def self.from_response(data) raise NotImplementedError, "#{name} must implement .from_response" end |
Instance Method Details
#to_h ⇒ Object
Convert model to hash for API requests Subclasses can override this for custom serialization Default implementation uses compact to remove nil values
24 25 26 |
# File 'lib/petstore_api_client/models/base.rb', line 24 def to_h attributes.compact end |