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.



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

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

Class Method Details

.custom_headersObject



18
19
20
# File 'lib/dina/models/base_model.rb', line 18

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

.endpoint_pathObject



11
12
# File 'lib/dina/models/base_model.rb', line 11

def self.endpoint_path
end

.find_by_group(group, page: 1, per: 50) ⇒ Object



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

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

.propertiesObject



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

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

.siteObject



14
15
16
# File 'lib/dina/models/base_model.rb', line 14

def self.site
  Dina::Authentication.endpoint_url + "/" + endpoint_path
end

Instance Method Details

#english_descriptionObject



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

def english_description
  if self.respond_to?(:multilingualDescription)
    multilingualDescription[:descriptions].select{|o| o[:lang] == "en"}.first[:desc]
  end
end

#french_descriptionObject



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

def french_description
  if self.respond_to?(:multilingualDescription)
    multilingualDescription[:descriptions].select{|o| o[:lang] == "fr"}.first[:desc]
  end
end