Class: Dina::BaseModel
- Inherits:
-
JsonApiClient::Resource
- Object
- JsonApiClient::Resource
- Dina::BaseModel
- Includes:
- JsonApiClient::Helpers::Callbacks
- Defined in:
- lib/dina/models/base_model.rb
Direct Known Subclasses
Assemblage, Attachment, BaseSearch, CollectingEvent, Collection, CollectionMethod, CollectionSequenceGenerator, Derivative, File, Identifier, IndexSet, Institution, ManagedAttribute, MaterialSample, MolecularSample, NgsWorkflow, ObjectStore, ObjectStoreManagedAttribute, ObjectSubtype, Organism, Organization, PcrBatch, PcrPrimer, Person, PreparationMethod, PreparationType, Product, Project, Protocol, Region, StorageUnit, StorageUnitType, ThermocyclerProfile, Transaction, User
Class Method Summary collapse
-
.custom_headers ⇒ Object
injects keycloak bearer token with all json_api_client calls.
-
.endpoint_path ⇒ Object
Required by json_api_client Set by all child classes.
-
.find_by_group(group, page: 1, per: 50) ⇒ Object
helper method for all child classes to retrieve records by group.
-
.properties ⇒ Object
helper method to retrieve all properties for a class.
-
.site ⇒ Object
Required by json_api_client.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ BaseModel
constructor
A new instance of BaseModel.
Constructor Details
#initialize(params = {}) ⇒ BaseModel
Returns a new instance of BaseModel.
40 41 42 43 44 45 |
# File 'lib/dina/models/base_model.rb', line 40 def initialize(params = {}) symbolized_params = params.transform_keys(&:to_sym) params["id"] = SecureRandom.uuid if !symbolized_params[:id] super extend_model_methods end |
Class Method Details
.custom_headers ⇒ Object
injects keycloak bearer token with all json_api_client calls
26 27 28 |
# File 'lib/dina/models/base_model.rb', line 26 def self.custom_headers { content_type: "application/vnd.api+json", authorization: Dina.header } end |
.endpoint_path ⇒ Object
Required by json_api_client Set by all child classes
15 16 |
# File 'lib/dina/models/base_model.rb', line 15 def self.endpoint_path end |
.find_by_group(group, page: 1, per: 50) ⇒ Object
helper method for all child classes to retrieve records by group
31 32 33 |
# File 'lib/dina/models/base_model.rb', line 31 def self.find_by_group(group, page: 1, per: 50) self.where("group.groupName": group).page(page).per(per) end |
.properties ⇒ Object
helper method to retrieve all properties for a class
36 37 38 |
# File 'lib/dina/models/base_model.rb', line 36 def self.properties self.schema.instance_values["properties"] end |
.site ⇒ Object
Required by json_api_client
19 20 21 22 23 |
# File 'lib/dina/models/base_model.rb', line 19 def self.site raise ConfigItemMissing, "Missing endpoint_url from config. Perhaps Dina.config has not yet been called." unless Dina.config.endpoint_url raise PropertyInvalid, "Missing endpoint_path in class." unless !endpoint_path.nil? Dina.config.endpoint_url + "/" + endpoint_path.to_s end |