Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wings] Remove method missing #3952

Merged
merged 2 commits into from
Sep 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions lib/wings/hydra/pcdm/models/concerns/pcdm_valkyrie_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,27 @@ def in_collection_ids(valkyrie: false)
in_collections(valkyrie: valkyrie).map(&:id)
end

def original_file
af_object = Wings::ActiveFedoraConverter.new(resource: self).convert
af_object.original_file
end

##
# Any method not implemented is sent to the ActiveFedora version of the resource.
def method_missing(name, *args, &block)
# TODO: Remove the puts and this method when all methods are valkyrized
# @return [Boolean] whether this instance is an audio.
def audio?
af_object = Wings::ActiveFedoraConverter.new(resource: self).convert
unless af_object.respond_to? name
Rails.logger.warn "#{af_object.class} does not respond to method #{name}"
super
end
Rails.logger.info "Calling through Method Missing with name: #{name} args: #{args} block_given? #{block_given?}"
args.delete_if { |arg| arg.is_a?(Hash) && arg.key?(:valkyrie) }
return af_object.send(name, args, block) if block_given?
return af_object.send(name, args) if args.present?
af_object.send(name)
af_object.audio?
end

def respond_to_missing?(_name, _include_private = false)
true
# TODO: This can be removed when we upgrade to ActiveFedora 12.0
# @return [String] the etag from the response headers
#
# @raise [RuntimeError] when the resource is new and has no etag
# @raise [Ldp::Gone] when the resource is deleted
def etag
raise "Unable to produce an etag for a unsaved object" unless persisted?
af_object = Wings::ActiveFedoraConverter.new(resource: self).convert
af_object.ldp_source.head.etag
end

# @param valkyrie [Boolean] Should the returned ids be for Valkyrie or AF objects?
Expand Down