class Fortnox::API::Types::Model
Public Class Methods
is?(*_args)
click to toggle source
# File lib/fortnox/api/types/model.rb, line 18 def self.is?(*_args) end
new(input_attributes)
click to toggle source
Calls superclass method
# File lib/fortnox/api/types/model.rb, line 9 def initialize(input_attributes) if (missing_key = first_missing_required_key(input_attributes)) error_message = "Missing attribute #{missing_key.inspect} in attributes: #{input_attributes}" raise Fortnox::API::MissingAttributeError, error_message end super end
Private Instance Methods
first_missing_required_key(attributes)
click to toggle source
# File lib/fortnox/api/types/model.rb, line 31 def first_missing_required_key(attributes) missing_keys(attributes).find do |name| attribute = self.class.schema[name] attribute.respond_to?(:options) && attribute.options[:required] end end
missing_keys(attributes)
click to toggle source
# File lib/fortnox/api/types/model.rb, line 22 def missing_keys(attributes) non_nil_attributes = attributes.reject { |_, value| value.nil? } attribute_keys = non_nil_attributes.keys schema_keys = self.class.schema.keys schema_keys - attribute_keys end