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
AcquisitionEvent, Assemblage, Attachment, BaseSearch, CollectingEvent, CollectingMethod, Collection, 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 keybloak 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
- #english_description ⇒ Object
- #french_description ⇒ Object
-
#initialize(params = {}) ⇒ BaseModel
constructor
A new instance of BaseModel.
Constructor Details
#initialize(params = {}) ⇒ BaseModel
Returns a new instance of BaseModel.
37 38 39 40 41 |
# File 'lib/dina/models/base_model.rb', line 37 def initialize(params = {}) symbolized_params = params.transform_keys(&:to_sym) params["id"] = SecureRandom.uuid if !symbolized_params[:id] super end |
Class Method Details
.custom_headers ⇒ Object
injects keybloak bearer token with all json_api_client calls
23 24 25 |
# File 'lib/dina/models/base_model.rb', line 23 def self.custom_headers { content_type: "application/vnd.api+json", authorization: Dina::Authentication.header } end |
.endpoint_path ⇒ Object
Required by json_api_client Set by all child classes
13 14 |
# File 'lib/dina/models/base_model.rb', line 13 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
28 29 30 |
# File 'lib/dina/models/base_model.rb', line 28 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
33 34 35 |
# File 'lib/dina/models/base_model.rb', line 33 def self.properties self.schema.instance_values["properties"] end |
.site ⇒ Object
Required by json_api_client
17 18 19 20 |
# File 'lib/dina/models/base_model.rb', line 17 def self.site raise ConfigItemMissing, "Missing endpoint_url from config. Perhaps Dina::Authentication.config has not yet been called." unless Dina::Authentication.endpoint_url Dina::Authentication.endpoint_url + "/" + endpoint_path end |
Instance Method Details
#english_description ⇒ Object
43 44 45 46 47 |
# File 'lib/dina/models/base_model.rb', line 43 def english_description if self.respond_to?(:multilingualDescription) multilingualDescription[:descriptions].select{|o| o[:lang] == "en"}.first[:desc] end end |
#french_description ⇒ Object
49 50 51 52 53 |
# File 'lib/dina/models/base_model.rb', line 49 def french_description if self.respond_to?(:multilingualDescription) multilingualDescription[:descriptions].select{|o| o[:lang] == "fr"}.first[:desc] end end |