Skip to content

Instantly share code, notes, and snippets.

@dchandekstark
Created May 15, 2013 17:16
Show Gist options
  • Save dchandekstark/5585609 to your computer and use it in GitHub Desktop.
Save dchandekstark/5585609 to your computer and use it in GitHub Desktop.
ActiveFedora decorators
ActiveFedora::Base.class_eval do
# method_missing is defined, so adding methods
def auditable?
begin
self.is_a? ActiveFedora::Auditable
rescue
false
end
end
def has_permissions?
self.is_a? Hydra::ModelMixins::RightsMetadata
end
def governable?
!is_governed_by_association.nil?
end
private
def governed_by_association
self.reflections.each do |name, reflection|
# FIXME add class name condition, i.e.:
# && reflection.class_name == [Hydra configured policy class or Hydra::AdminPolicy]
return reflection if reflection.macro == :belongs_to && reflection.options[:property] == :is_governed_by
end
end
end
ActiveFedora::Datastream.class_eval do
def method_missing(meth)
case
when meth == :current_version? then @current_version ||= (new? || versions.empty? || dsVersionID == versions.first.dsVersionID)
when meth == :content_is_url? then external? || redirect?
when meth == :content_is_uploadable? then managed? || inline?
when meth == :content_is_editable? then !content_is_url? && content_is_text?
when meth == :content_is_text? then !mimeType.blank? && (mimeType.start_with?('text/') || FcrepoAdmin.extra_text_mime_types.include?(mimeType))
else super
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment