Class: ActiveFedora::StreamAttribute Abstract

Inherits:
DelegatedAttribute show all
Defined in:
lib/active_fedora/attributes/stream_attribute.rb

Overview

This class is abstract.

Abstract class for attributes that are delegated to a serialized representation such as a NonRDFSource

Direct Known Subclasses

OmAttribute, RdfDatastreamAttribute

Instance Attribute Summary collapse

Attributes inherited from DelegatedAttribute

#field, #multiple

Instance Method Summary collapse

Constructor Details

#initialize(field, args = {}) ⇒ StreamAttribute

Returns a new instance of StreamAttribute.

Parameters:

  • field (Symbol)

    the field to find or create

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :delegate_target (String)

    the path to the delegate

  • :klass (Class)

    the class to create

  • :multiple (true, false) — default: false

    true for multi-value fields

  • :at (Array<Symbol>)

    path to a deep node



20
21
22
23
24
25
# File 'lib/active_fedora/attributes/stream_attribute.rb', line 20

def initialize(field, args={})
  super
  self.delegate_target  = args.fetch(:delegate_target)
  self.target_class     = args.fetch(:klass)
  self.at               = args.fetch(:at, nil)
end

Instance Attribute Details

#atString

Returns the current value of at.

Returns:

  • (String)

    the current value of at



10
11
12
# File 'lib/active_fedora/attributes/stream_attribute.rb', line 10

def at
  @at
end

#delegate_targetString

Returns the current value of delegate_target.

Returns:

  • (String)

    the current value of delegate_target



10
11
12
# File 'lib/active_fedora/attributes/stream_attribute.rb', line 10

def delegate_target
  @delegate_target
end

#target_classString

Returns the current value of target_class.

Returns:

  • (String)

    the current value of target_class



10
11
12
# File 'lib/active_fedora/attributes/stream_attribute.rb', line 10

def target_class
  @target_class
end

Instance Method Details

#primary_solr_nameObject

Gives the primary solr name for a column. If there is more than one indexer on the field definition, it gives the first

Raises:

  • (NoMethodError)


28
29
30
31
32
# File 'lib/active_fedora/attributes/stream_attribute.rb', line 28

def primary_solr_name
  @datastream ||= target_class.new
  raise NoMethodError, "the file '#{target_class}' doesn't respond to 'primary_solr_name'" unless @datastream.respond_to?(:primary_solr_name)
  @datastream.primary_solr_name(field, delegate_target)
end

#typeObject

Raises:

  • (NoMethodError)


34
35
36
37
# File 'lib/active_fedora/attributes/stream_attribute.rb', line 34

def type
  raise NoMethodError, "the file '#{target_class}' doesn't respond to 'type'" unless target_class.respond_to?(:type)
  target_class.type(field)
end