module ActiveFedora::Attributes::ClassMethods

def add_attribute_indexing_config(name, &block)

def add_attribute_indexing_config(name, &block)
  index_config[name] ||= ActiveFedora::Indexing::Map::IndexObject.new(name, &block)
end

def association_attributes

Attributes that represent associations to other repository objects
def association_attributes
  outgoing_reflections.values.map { |reflection| reflection.foreign_key.to_s }
end

def attribute_class(klass)

def attribute_class(klass)
  if klass < ActiveFedora::RDFDatastream
    RdfDatastreamAttribute
  else
    OmAttribute
  end
end

def attribute_names

def attribute_names
  @attribute_names ||= delegated_attributes.keys + association_attributes - system_attributes
end

def attributes_with_defaults

From ActiveFedora::FedoraAttributes
def attributes_with_defaults
  ['type', 'rdf_label']
end

def create_attribute_reader(field, _dsid, _args)

def create_attribute_reader(field, _dsid, _args)
  define_method field do |*opts|
    array_reader(field, *opts)
  end
end

def create_attribute_setter(field, _dsid, _args)

def create_attribute_setter(field, _dsid, _args)
  define_method "#{field}=".to_sym do |v|
    self[field] = v
  end
end

def datastream_class_for_name(dsid)

Returns:
  • (Class) - the class of the datastream

Parameters:
  • dsid (String) -- the datastream id
def datastream_class_for_name(dsid)
  reflection = _reflect_on_association(dsid.to_sym)
  reflection ? reflection.klass : ActiveFedora::File
end

def define_active_triple_accessor(name, properties, &block)

def define_active_triple_accessor(name, properties, &block)
  warn_duplicate_predicates name, properties
  properties = { multiple: true }.merge(properties)
  find_or_create_defined_attribute(name, ActiveTripleAttribute, properties)
  raise ArgumentError, "#{name} is a keyword and not an acceptable property name." if protected_property_name? name
  reflection = ActiveFedora::Attributes::PropertyBuilder.build(self, name, properties, &block)
  ActiveTriples::Reflection.add_reflection self, name, reflection
  add_attribute_indexing_config(name, &block) if block_given?
end

def define_delegated_accessor(fields, delegate_target, options, &block)

def define_delegated_accessor(fields, delegate_target, options, &block)
  define_attribute_methods fields
  fields.each do |f|
    klass = datastream_class_for_name(delegate_target)
    attribute_properties = options.merge(delegate_target: delegate_target, klass: klass)
    find_or_create_defined_attribute f, attribute_class(klass), attribute_properties
    create_attribute_reader(f, delegate_target, options)
    create_attribute_setter(f, delegate_target, options)
    add_attribute_indexing_config(f, &block) if block_given?
  end
end

def defined_attributes

def defined_attributes
  Deprecation.warn Attributes, "defined_attributes has been renamed to delegated_attributes. defined_attributes will be removed in ActiveFedora 9"
  delegated_attributes
end

def delegated_attributes

def delegated_attributes
  @delegated_attributes ||= {}.with_indifferent_access
  return @delegated_attributes unless superclass.respond_to?(:delegated_attributes) && value = superclass.delegated_attributes
  @delegated_attributes = value.dup if @delegated_attributes.empty?
  @delegated_attributes
end

def delegated_attributes=(val)

def delegated_attributes=(val)
  @delegated_attributes = val
end

def find_or_create_defined_attribute(field, klass, args)

Returns:
  • (DelegatedAttribute) - the found or created attribute

Options Hash: (**args)
  • :at (Array) -- path to a deep node
  • :multiple (true, false) -- true for multi-value fields
  • :klass (Class) -- the class to create
  • :delegate_target (String) -- the path to the delegate

Parameters:
  • args (Hash) --
  • klass (Class) -- the class to use to delegate the attribute (e.g.
  • field (Symbol) -- the field to find or create
def find_or_create_defined_attribute(field, klass, args)
  delegated_attributes[field] ||= klass.new(field, args)
end

def has_attributes(*fields, &block)

def has_attributes(*fields, &block)
  options = fields.pop
  delegate_target = options.delete(:datastream)
  raise ArgumentError, "You must provide a datastream to has_attributes" if delegate_target.blank?
  Deprecation.warn Attributes, "has_attributes is deprecated and will be removed in ActiveFedora 10.0. Consider using the Form pattern to save all related models or directly delegate the properties and save the target separately"
  define_delegated_accessor(fields, delegate_target, options, &block)
end

def local_attributes

Attributes that are asserted about this RdfSource (not on a datastream)
def local_attributes
  association_attributes + properties.keys - system_attributes
end

def multiple?(field)

Returns:
  • (Boolean) -

Parameters:
  • field (Symbol) -- the field to query
def multiple?(field)
  raise UnknownAttributeError.new(nil, field, self) unless delegated_attributes.key?(field)
  delegated_attributes[field].multiple
end

def property(name, properties = {}, &block)

def property(name, properties = {}, &block)
  if properties.key?(:predicate)
    define_active_triple_accessor(name, properties, &block)
  elsif properties.key?(:delegate_to)
    Deprecation.warn Attributes, "delegated properties are deprecated and will be removed in ActiveFedora 10.0. Consider using the Form pattern to save all related models or directly delegate the properties and save the target separately"
    define_delegated_accessor([name], properties.delete(:delegate_to), properties.reverse_merge(multiple: true), &block)
  else
    raise "You must provide `:delegate_to' or `:predicate' options to property"
  end
end

def system_attributes

Attributes that are required by ActiveFedora and Fedora
def system_attributes
  ['has_model', 'create_date', 'modified_date']
end

def unique?(field)

Returns:
  • (Boolean) -

Parameters:
  • field (Symbol) -- the field to query
def unique?(field)
  !multiple?(field)
end

def warn_duplicate_predicates(new_name, new_properties)

def warn_duplicate_predicates(new_name, new_properties)
  new_predicate = new_properties[:predicate]
  properties.select { |_k, existing| existing.predicate == new_predicate }.each do |key, _value|
    ActiveFedora::Base.logger.warn "Same predicate (#{new_predicate}) used for properties #{key} and #{new_name}"
  end
end