class Redox::Models::AbstractModel
Constants
- HIGH_LEVEL_KEYS
Public Class Methods
from_response(response)
click to toggle source
# File lib/redox/models/model.rb, line 37 def self.from_response(response) model = Model.new model.response = response HIGH_LEVEL_KEYS.each do |k| begin model.send("#{k}=", Module.const_get("Redox::Models::#{k}").new(response[k])) if response[k] rescue end end return model end
from_response_inflected(response)
click to toggle source
# File lib/redox/models/model.rb, line 51 def self.from_response_inflected(response) model = self.from_response(response) if (model.response.ok?) data = model.response.parsed_response if data.respond_to?(:keys) model_class = nil if model.meta&.data_model model_class = "Redox::Models::#{model.meta.data_model}" begin model_class = Object.const_get(model_class) rescue NameError model_class = nil end end data.keys.each do |key| next if HIGH_LEVEL_KEYS.include?(key.to_s) helper_name = key.to_s.downcase.to_sym if model_class.nil? model.define_singleton_method(helper_name) { data[key] } else if data[key].is_a?(Array) model.define_singleton_method(helper_name) { data[key].map {|obj| model_class.new(obj) } } else model.define_singleton_method(helper_name) { model_class.new(data[key]) } end end end end end return model end
Public Instance Methods
insurances()
click to toggle source
# File lib/redox/models/model.rb, line 33 def insurances (self.patient&.insurances || []) + (self.visit&.insurances || []) end
to_json(args = {})
click to toggle source
# File lib/redox/models/model.rb, line 29 def to_json(args = {}) return self.to_h.to_json end