Sha256: 780130720b1628d628367e03b0536106781ee78c48a051f34df3a3cf4ad276dd

Contents?: true

Size: 960 Bytes

Versions: 3

Compression:

Stored size: 960 Bytes

Contents

require 'active_support/descendants_tracker'

module ValkyrieActiveFedora
  # This class extends ActiveFedora::Base to add in methods that allow
  # an instance of the class to be converted to a Valkyrie::Resource.
  #
  # =The Basics
  #   class Oralhistory < ValkyrieActiveFedora::Base
  #     property :creator, predicate: RDF::Vocab::DC.creator
  #   end
  class Base < ActiveFedora::Base
    def valkyrie_resource
      "Valkyrie::#{self.class}".constantize
    rescue NameError
      nil
    end

    def attributes_including_linked_ids
      local_attributes = attributes.dup
      linked_id_keys.each do |id_method|
        local_attributes.merge!(id_method => send(id_method)).with_indifferent_access
      end
      local_attributes
    end

    def linked_id_keys
      @linked_id_keys ||= reflections.keys.map do |key|
        id_method = "#{key.to_s.singularize}_ids"
        id_method if respond_to? id_method
      end.compact
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
valkyrie_active_fedora-0.0.5 lib/valkyrie_active_fedora/base.rb
valkyrie_active_fedora-0.0.4 lib/valkyrie_active_fedora/base.rb
valkyrie_active_fedora-0.0.3 lib/valkyrie_active_fedora/base.rb