module ActiveFedora::Attributes::ClassMethods

Public Instance Methods

association_attributes() click to toggle source

Attributes that represent associations to other repository objects

# File lib/active_fedora/attributes.rb, line 105
def association_attributes
  outgoing_reflections.values.map { |reflection| reflection.foreign_key.to_s }
end
attribute_names() click to toggle source
# File lib/active_fedora/attributes.rb, line 85
def attribute_names
  @attribute_names ||= delegated_attributes.keys + association_attributes - system_attributes
end
attributes_with_defaults() click to toggle source

From ActiveFedora::FedoraAttributes

# File lib/active_fedora/attributes.rb, line 100
def attributes_with_defaults
  ['type', 'rdf_label']
end
delegated_attributes() click to toggle source
# File lib/active_fedora/attributes.rb, line 109
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
delegated_attributes=(val) click to toggle source
# File lib/active_fedora/attributes.rb, line 116
def delegated_attributes=(val)
  @delegated_attributes = val
end
local_attributes() click to toggle source

Attributes that are asserted about this RdfSource (not on a datastream)

# File lib/active_fedora/attributes.rb, line 90
def local_attributes
  association_attributes + properties.keys - system_attributes
end
multiple?(field) click to toggle source

Reveal if the attribute is multivalued @param [Symbol] field the field to query @return [Boolean]

# File lib/active_fedora/attributes.rb, line 130
def multiple?(field)
  raise UnknownAttributeError.new(nil, field, self) unless delegated_attributes.key?(field)
  delegated_attributes[field].multiple
end
property(name, properties = {}, &block) click to toggle source
# File lib/active_fedora/attributes.rb, line 135
def property(name, properties = {}, &block)
  raise ArgumentError, "You must provide a `:predicate' option to property" unless properties.key?(:predicate)
  define_active_triple_accessor(name, properties, &block)
end
system_attributes() click to toggle source

Attributes that are required by ActiveFedora and Fedora

# File lib/active_fedora/attributes.rb, line 95
def system_attributes
  ['has_model', 'create_date', 'modified_date']
end
unique?(field) click to toggle source

Reveal if the attribute has been declared unique @param [Symbol] field the field to query @return [Boolean]

# File lib/active_fedora/attributes.rb, line 123
def unique?(field)
  !multiple?(field)
end

Private Instance Methods

add_attribute_indexing_config(name, &block) click to toggle source
# File lib/active_fedora/attributes.rb, line 153
def add_attribute_indexing_config(name, &block)
  index_config[name] ||= ActiveFedora::Indexing::Map::IndexObject.new(name, &block)
end
define_active_triple_accessor(name, properties, &block) click to toggle source
# File lib/active_fedora/attributes.rb, line 142
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
find_or_create_defined_attribute(field, klass, args) click to toggle source

@param [Symbol] field the field to find or create @param [Class] klass the class to use to delegate the attribute (e.g.

ActiveTripleAttribute)

@param [Hash] args @option args [String] :delegate_target the path to the delegate @option args [Class] :klass the class to create @option args [true,false] :multiple (false) true for multi-value fields @option args [Array<Symbol>] :at path to a deep node @return [DelegatedAttribute] the found or created attribute

# File lib/active_fedora/attributes.rb, line 173
def find_or_create_defined_attribute(field, klass, args)
  delegated_attributes[field] ||= klass.new(field, args)
end
warn_duplicate_predicates(new_name, new_properties) click to toggle source
# File lib/active_fedora/attributes.rb, line 157
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