Class: ActiveFedora::Associations::Builder::Contains

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

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Association

#mixin, #model, #name, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SingularAssociation

constructable?, define_accessors, define_constructors

Methods inherited from Association

build, #build, #configure_dependency, define_accessors, define_callbacks, define_writers, #predicate, #translate_property_to_predicate

Constructor Details

#initialize(model, name, options) ⇒ Contains

Returns a new instance of Contains


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

def initialize(model, name, options)
  super
  options[:class_name] = 'ActiveFedora::File' if options[:class_name].blank?
end

Class Method Details

.define_readers(mixin, name) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_fedora/associations/builder/contains.rb', line 18

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

Instance Method Details

#validate_optionsObject


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

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