Class: ActiveFedora::Associations::Builder::HasSubresource

Inherits:
SingularAssociation show all
Defined in:
lib/active_fedora/associations/builder/has_subresource.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Association

#inversed, #owner, #reflection, #target

Class Method Summary collapse

Methods inherited from SingularAssociation

#build, #create, #create!, #reader, #writer

Methods inherited from Association

#association_scope, #initialize, #initialize_attributes, #load_target, #loaded!, #loaded?, #reload, #reset, #reset_scope, #scope, #set_inverse_instance, #stale_target?, #target_scope

Constructor Details

This class inherits a constructor from ActiveFedora::Associations::Association

Class Method Details

.create_reflection(model, name, scope, options, extension = nil) ⇒ Object



11
12
13
14
# File 'lib/active_fedora/associations/builder/has_subresource.rb', line 11

def self.create_reflection(model, name, scope, options, extension = nil)
  options[:class_name] = 'ActiveFedora::File' if options[:class_name].blank?
  super(model, name, scope, options, extension)
end

.define_readers(mixin, name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_fedora/associations/builder/has_subresource.rb', line 22

def self.define_readers(mixin, name)
  mixin.send(:define_method, name) do |*params|
    association(name).reader(*params).tap do |file|
      set_uri = uri.is_a?(RDF::URI) ? uri.value.present? : uri.present?
      if set_uri
        file_uri = "#{uri}/#{name}"
        begin
          file.uri = file_uri
        rescue ActiveFedora::AlreadyPersistedError
        end
      end
      if file.respond_to?(:exists!)
        file.exists! if contains_assertions.include?(file_uri)
      end
    end
  end
end

.macroObject



3
4
5
# File 'lib/active_fedora/associations/builder/has_subresource.rb', line 3

def self.macro
  :has_subresource
end

.valid_options(options) ⇒ Object



7
8
9
# File 'lib/active_fedora/associations/builder/has_subresource.rb', line 7

def self.valid_options(options)
  super + [:autocreate, :block]
end

.validate_options(options) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/active_fedora/associations/builder/has_subresource.rb', line 16

def self.validate_options(options)
  super
  return unless options[:class_name] && !options[:class_name].is_a?(String)
  raise ArgumentError, ":class_name must be a string for contains '#{name}'"
end