class ActiveFedora::Associations::AssociationProxy
def flatten_deeper(array)
Array#flatten has problems with recursive arrays before Ruby 1.9.2.
def flatten_deeper(array) array.collect { |element| (element.respond_to?(:flatten) && !element.is_a?(Hash)) ? element.flatten : element }.flatten end
def flatten_deeper(array)
def flatten_deeper(array) array.flatten end
def foreign_key_present
still being a new record). Currently, only +belongs_to+ presents
available for an association without having the object itself (and
Can be overwritten by associations that might have the foreign key
def foreign_key_present false end
def initialize(owner, reflection)
def initialize(owner, reflection) @owner, @reflection = owner, reflection @updated = false # reflection.check_validity! # Array.wrap(reflection.options[:extend]).each { |ext| proxy_extend(ext) } reset nd
def load_target
ActiveFedora::ObjectNotFoundError is rescued within the method, and it is
+load_target+ unconditionally to get the \target.
If the \target is already \loaded it is just returned. Thus, you can call
which is expected to be provided by descendants.
This method is abstract in the sense that it relies on +find_target+,
Loads the \target if needed and returns it.
def load_target return nil unless defined?(@loaded) if !loaded? and (!@owner.new_record? || foreign_key_present) @target = find_target end if @target.nil? reset else @loaded = true @target end end
def loaded
def loaded @loaded = true end
def loaded?
def loaded? @loaded end
def method_missing(method, *args)
def method_missing(method, *args) if load_target unless @target.respond_to?(method) message = "undefined method `#{method.to_s}' for \"#{@target}\":#{@target.class.to_s}" raise NoMethodError, message end if block_given? @target.send(method, *args) { |*block_args| yield(*block_args) } else @target.send(method, *args) end end end
def raise_on_type_mismatch(record)
the kind of the class of the associated objects. Meant to be used as
Raises ActiveFedora::AssociationTypeMismatch unless +record+ is of
def raise_on_type_mismatch(record) unless record.is_a?(@reflection.klass) || record.is_a?(@reflection.class_name.constantize) message = "#{@reflection.class_name}(##{@reflection.klass.object_id}) expected, got #{record.class}(##{record.class.object_id})" raise ActiveFedora::AssociationTypeMismatch, message end end
def reload
def reload reset load_target self unless @target.nil? end
def reset
def reset @loaded = false @target = nil end
def set_belongs_to_association_for(record)
Assigns the ID of the owner to the corresponding foreign key in +record+.
def set_belongs_to_association_for(record) unless @owner.new_record? record.add_relationship(@reflection.options[:property], @owner) end end
def target
def target @target end
def target=(target)
def target=(target) @target = target loaded end