module FmRest
module Spyke
class Portal < ::Spyke::Associations::HasMany
def initialize(*args)
super
@options[:uri] = ""
end
def portal_key
(@options[:portal_key] || name).to_s
end
def attribute_prefix
(@options[:attribute_prefix] || portal_key).to_s
end
def parent_changes_applied
each(&:changes_applied)
end
def <<(*records)
records.flatten.each { |r| add_to_parent(r) }
self
end
alias_method :push, :<<
alias_method :concat, :<<
def _remove_marked_for_destruction
find_some.reject!(&:marked_for_destruction?)
end
private
def primary_key; end
def uri; nil; end
def embedded_data
parent.attributes[portal_key]
end
def add_to_parent(record)
raise ArgumentError, "Expected an instance of #{klass}, got a #{record.class} instead" unless record.kind_of?(klass)
find_some << record
record.embedded_in_portal
record
end
end
end
end