Module: ActiveShotgun::Model::Read

Defined in:
lib/active_shotgun/model/read.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#attributesObject



6
7
8
9
10
# 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

#initialize(new_attributes = {}, new_relations = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# 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

#reloadObject



31
32
33
# File 'lib/active_shotgun/model/read.rb', line 31

def reload
  self.class.find(id)
end

#writable_attributesObject



12
13
14
15
16
# 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