Class: Dina::BaseModel

Inherits:
JsonApiClient::Resource
  • Object
show all
Includes:
JsonApiClient::Helpers::Callbacks
Defined in:
lib/dina/models/base_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ BaseModel

Returns a new instance of BaseModel.



46
47
48
49
50
51
# File 'lib/dina/models/base_model.rb', line 46

def initialize(params = {})
  symbolized_params = params.transform_keys(&:to_sym)
  params["id"] = SecureRandom.uuid_v7 if !symbolized_params[:id]
  super
  extend_model_methods
end

Class Method Details

.custom_headersObject

injects keycloak bearer token with all json_api_client calls



32
33
34
# File 'lib/dina/models/base_model.rb', line 32

def self.custom_headers
  { content_type: "application/vnd.api+json", authorization: Dina.header }
end

.endpoint_pathObject

Required by json_api_client Set by all child classes



21
22
# File 'lib/dina/models/base_model.rb', line 21

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



37
38
39
# File 'lib/dina/models/base_model.rb', line 37

def self.find_by_group(group, page: 1, per: 50)
  self.where("group.groupName": group).page(page).per(per)
end

.propertiesObject

helper method to retrieve all properties for a class



42
43
44
# File 'lib/dina/models/base_model.rb', line 42

def self.properties
  self.schema.instance_values["properties"]
end

.siteObject

Required by json_api_client

Raises:



25
26
27
28
29
# File 'lib/dina/models/base_model.rb', line 25

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