# File lib/pupper/model.rb, line 37 def primary_key attributes.fetch(self.class.primary_key) end
module Pupper::Model
Public Class Methods
new(**args)
click to toggle source
Calls superclass method
# File lib/pupper/model.rb, line 21 def initialize(**args) assocs, attrs = args.partition do |attr, value| attr.to_s =~ /_u?id$/ || value.is_a?(Hash) || value.is_a?(Array) end.map(&Hash.method(:[])) assocs = build_associations(assocs) [attrs, assocs].map { |args| args.slice!(*self.class._attributes) } super(**attrs, **assocs) changes_applied backend.register_model(self) unless backend == :none end
Public Instance Methods
backend()
click to toggle source
@overload backend=(class_or_symbol)
Declare whether or not the model has a corresponding API client or not. (default: including class, plural, + client, e.g. `Form` => `FormsClient`) == Parameters: class_or_symbol:: `:none` if the model has no API, constant otherwise.
# File lib/pupper/model.rb, line 64 def backend @backend ||= "#{model_name.name.pluralize}Client".constantize.new end
primary_key()
click to toggle source
to_json(*)
click to toggle source
# File lib/pupper/model.rb, line 69 def to_json(*) attributes.except(*excluded_attrs).to_json end