Sha256: d7f4d9ca0e6539d840f08f10b611cab0f09caf77872f05af90960d7a860472b2

Contents?: true

Size: 837 Bytes

Versions: 61

Compression:

Stored size: 837 Bytes

Contents

module CurationConcerns::ParentContainer
  extend ActiveSupport::Concern

  included do
    helper_method :parent
  end

  # TODO: this is slow, refactor to return a Presenter (fetch from solr)
  def parent
    @parent ||= new_or_create? ? find_parent_by_id : lookup_parent_from_child
  end

  def find_parent_by_id
    ActiveFedora::Base.find(parent_id)
  end

  def lookup_parent_from_child
    # in_objects method is inherited from Hydra::PCDM::ObjectBehavior
    return curation_concern.in_objects.first if curation_concern
    return CurationConcerns::ParentService.parent_for(@presenter.id) if @presenter
    raise "no child"
  end

  def parent_id
    @parent_id ||= new_or_create? ? params[:parent_id] : lookup_parent_from_child.id
  end

  protected

    def new_or_create?
      %w(create new).include? action_name
    end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.7.7 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-2.0.0 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-2.0.0.rc2 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.7.6 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.7.5 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.7.4 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.7.3 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.7.2 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-2.0.0.rc1 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.7.1 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.7.0 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.7.0.beta1 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.6.3 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.6.2 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.6.1 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.6.0 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.5.0 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.4.0 app/controllers/concerns/curation_concerns/parent_container.rb
curation_concerns-1.3.3 app/controllers/concerns/curation_concerns/parent_container.rb