class Spyke::Associations::Association

Attributes

name[R]
parent[R]

Public Class Methods

new(klass, parent, name, options = {}) click to toggle source
Calls superclass method
# File lib/spyke/associations/association.rb, line 9
def initialize(klass, parent, name, options = {})
  super(klass, options)
  @parent, @name = parent, name
end

Public Instance Methods

assign_nested_attributes(attributes) click to toggle source
# File lib/spyke/associations/association.rb, line 18
def assign_nested_attributes(attributes)
  update_parent new(attributes)
end
build(*args)
Alias for: new
create(attributes = {}) click to toggle source
Calls superclass method
# File lib/spyke/associations/association.rb, line 22
def create(attributes = {})
  add_to_parent super
end
load() click to toggle source
# File lib/spyke/associations/association.rb, line 14
def load
  find_one # Override for plural associations that return an association object
end
new(*args) click to toggle source
Calls superclass method
# File lib/spyke/associations/association.rb, line 26
def new(*args)
  add_to_parent super
end
Also aliased as: build

Private Instance Methods

add_to_parent(record) click to toggle source
# File lib/spyke/associations/association.rb, line 34
def add_to_parent(record)
  update_parent record
end
embedded_data() click to toggle source
# File lib/spyke/associations/association.rb, line 54
def embedded_data
  parent.attributes[name]
end
fetch() click to toggle source
Calls superclass method
# File lib/spyke/associations/association.rb, line 42
def fetch
  fetch_embedded || super
end
fetch_embedded() click to toggle source
# File lib/spyke/associations/association.rb, line 46
def fetch_embedded
  if embedded_data
    Result.new(data: embedded_data)
  elsif !uri
    Result.new(data: nil)
  end
end
foreign_key() click to toggle source
# File lib/spyke/associations/association.rb, line 38
def foreign_key
  (@options[:foreign_key] || "#{parent.class.model_name.element}_id").to_sym
end
update_parent(value) click to toggle source
# File lib/spyke/associations/association.rb, line 58
def update_parent(value)
  parent.attributes[name] = value
end