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



130
131
132
# File 'lib/active_fedora/attributes.rb', line 130

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

#attribute_namesObject



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

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

#defined_attributesObject



134
135
136
137
# File 'lib/active_fedora/attributes.rb', line 134

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

#delegated_attributesObject



139
140
141
142
143
144
# File 'lib/active_fedora/attributes.rb', line 139

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

#delegated_attributes=(val) ⇒ Object



146
147
148
# File 'lib/active_fedora/attributes.rb', line 146

def delegated_attributes= val
  @delegated_attributes = val
end

#has_attributes(*fields, &block) ⇒ Object

Raises:

  • (ArgumentError)


150
151
152
153
154
155
156
157
# File 'lib/active_fedora/attributes.rb', line 150

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. Instead use:\n  property #{fields.first.inspect}, delegate_to: '#{delegate_target}', ...")

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

#local_attributesObject

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



120
121
122
# File 'lib/active_fedora/attributes.rb', line 120

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:



169
170
171
172
# File 'lib/active_fedora/attributes.rb', line 169

def multiple?(field)
  raise UnknownAttributeError, "#{self} does not have an attribute `#{field}'" unless delegated_attributes.key?(field)
  delegated_attributes[field].multiple
end

#property(name, properties = {}, &block) ⇒ Object



174
175
176
177
178
179
180
181
182
# File 'lib/active_fedora/attributes.rb', line 174

def property name, properties={}, &block
  if properties.key?(:predicate)
    define_active_triple_accessor(name, properties, &block)
  elsif properties.key?(:delegate_to)
    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

#system_attributesObject

Attributes that are required by ActiveFedora and Fedora



125
126
127
# File 'lib/active_fedora/attributes.rb', line 125

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)


162
163
164
# File 'lib/active_fedora/attributes.rb', line 162

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