Module: ActiveFedora::Attributes::ClassMethods

Defined in:
lib/active_fedora/attributes.rb

Instance Method Summary collapse

Instance Method Details

#association_attributesObject

Attributes that represent associations to other repository objects



105
106
107
# File 'lib/active_fedora/attributes.rb', line 105

def association_attributes
  outgoing_reflections.values.map { |reflection| reflection.foreign_key.to_s }
end

#attribute_namesObject



85
86
87
# File 'lib/active_fedora/attributes.rb', line 85

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

#attributes_with_defaultsObject

From ActiveFedora::FedoraAttributes



100
101
102
# File 'lib/active_fedora/attributes.rb', line 100

def attributes_with_defaults
  ['type', 'rdf_label']
end

#delegated_attributesObject



109
110
111
112
113
114
# 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) ⇒ Object



116
117
118
# File 'lib/active_fedora/attributes.rb', line 116

def delegated_attributes=(val)
  @delegated_attributes = val
end

#local_attributesObject

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



90
91
92
# File 'lib/active_fedora/attributes.rb', line 90

def local_attributes
  association_attributes + properties.keys - system_attributes
end

#multiple?(field) ⇒ Boolean

Reveal if the attribute is multivalued

Parameters:

  • field (Symbol)

    the field to query

Returns:

  • (Boolean)

Raises:



130
131
132
133
# 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) ⇒ Object

Raises:

  • (ArgumentError)


135
136
137
138
# 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_attributesObject

Attributes that are required by ActiveFedora and Fedora



95
96
97
# File 'lib/active_fedora/attributes.rb', line 95

def system_attributes
  ['has_model', 'create_date', 'modified_date']
end

#unique?(field) ⇒ Boolean

Reveal if the attribute has been declared unique

Parameters:

  • field (Symbol)

    the field to query

Returns:

  • (Boolean)


123
124
125
# File 'lib/active_fedora/attributes.rb', line 123

def unique?(field)
  !multiple?(field)
end