module ActiveShotgun::Model::Read

Public Class Methods

new(new_attributes = {}, new_relations = {}) click to toggle source
# File lib/active_shotgun/model/read.rb, line 18
def initialize(new_attributes = {}, new_relations = {})
  new_attributes.slice(*self.class.shotgun_readable_fetched_attributes).each do |attribute, value|
    instance_variable_set("@#{attribute}", value)
  end
  self.class::BELONG_ASSOC.each do |assoc|
    next unless relation = new_relations[assoc]

    instance_variable_set("@#{assoc}_type", relation["type"])
    instance_variable_set("@#{assoc}_id", relation["id"])
    instance_variable_set("@#{assoc}", nil)
  end
end

Public Instance Methods

attributes() click to toggle source
# File lib/active_shotgun/model/read.rb, line 6
def attributes
  self.class.shotgun_readable_fetched_attributes.map do |attribute|
    [attribute, instance_variable_get("@#{attribute}")]
  end.to_h
end
reload() click to toggle source
# File lib/active_shotgun/model/read.rb, line 31
def reload
  self.class.find(id)
end
writable_attributes() click to toggle source
# File lib/active_shotgun/model/read.rb, line 12
def writable_attributes
  self.class.shotgun_writable_fetched_attributes.map do |attribute|
    [attribute, instance_variable_get("@#{attribute}")]
  end.to_h
end