class ActiveFedora::AssociationHash
reflections.
Used as an access method for associations on a model, given some
#
def [](name)
def [](name) association(name).reader if association(name) end
def []=(name, object)
def []=(name, object) association(name).writer(object) if association(name) end
def association(name)
def association(name) # Check to see if the key exists before casting to a symbol, because symbols # are not garbage collected in earlier versions of Ruby base.association(name.to_sym) if key?(name) end
def changed
def changed select do |_, obj| obj.changed? end end
def each
def each keys.each do |k| yield k, self[k] end end
def each_value
def each_value keys.each do |k| yield self[k] end end
def freeze
def freeze keys.each do |name| association(name).reader.freeze if association(name).loaded? end super end
def initialize(model, reflections)
def initialize(model, reflections) @base = model @reflections = reflections end
def key?(key)
manner that avoids generating extra symbols. Symbols are not garbage collected
Check that the key exists with indifferent access (symbol or string) in a
def key?(key) keys.include?(key) || keys.map(&:to_s).include?(key) end
def merge(other_hash)
def merge(other_hash) Merged.new(self, other_hash) end
def select
def select keys.each_with_object({}) do |k, h| if association(k).loaded? val = self[k] h[k] = val if yield k, val end end end
def values
def values keys.map { |k| self[k] } end