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



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

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

#attribute_namesObject



66
67
68
# File 'lib/active_fedora/attributes.rb', line 66

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

#attributes_with_defaultsObject

From ActiveFedora::FedoraAttributes



81
82
83
# File 'lib/active_fedora/attributes.rb', line 81

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

#delegated_attributesObject



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

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



97
98
99
# File 'lib/active_fedora/attributes.rb', line 97

def delegated_attributes=(val)
  @delegated_attributes = val
end

#local_attributesObject

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



71
72
73
# File 'lib/active_fedora/attributes.rb', line 71

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:



111
112
113
114
# File 'lib/active_fedora/attributes.rb', line 111

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)


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

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



76
77
78
# File 'lib/active_fedora/attributes.rb', line 76

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)


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

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