Class: ActiveFedora::DelegatedAttribute
- Inherits:
-
Object
- Object
- ActiveFedora::DelegatedAttribute
- Defined in:
- lib/active_fedora/delegated_attribute.rb
Overview
Represents the mapping between a model attribute and a field in a datastream
Instance Attribute Summary collapse
-
#at ⇒ Object
Returns the value of attribute at.
-
#datastream_class ⇒ Object
Returns the value of attribute datastream_class.
-
#dsid ⇒ Object
Returns the value of attribute dsid.
-
#field ⇒ Object
Returns the value of attribute field.
-
#multiple ⇒ Object
Returns the value of attribute multiple.
Instance Method Summary collapse
-
#initialize(field, dsid, datastream_class, args = {}) ⇒ DelegatedAttribute
constructor
A new instance of DelegatedAttribute.
-
#primary_solr_name ⇒ Object
Gives the primary solr name for a column.
- #reader(obj, *opts) ⇒ Object
- #type ⇒ Object
- #writer(obj, v) ⇒ Object
Constructor Details
#initialize(field, dsid, datastream_class, args = {}) ⇒ DelegatedAttribute
Returns a new instance of DelegatedAttribute.
7 8 9 10 11 12 13 |
# File 'lib/active_fedora/delegated_attribute.rb', line 7 def initialize(field, dsid, datastream_class, args={}) self.field = field self.dsid = dsid self.datastream_class = datastream_class self.multiple = args[:multiple].nil? ? false : args[:multiple] self.at = args[:at] end |
Instance Attribute Details
#at ⇒ Object
Returns the value of attribute at.
5 6 7 |
# File 'lib/active_fedora/delegated_attribute.rb', line 5 def at @at end |
#datastream_class ⇒ Object
Returns the value of attribute datastream_class.
5 6 7 |
# File 'lib/active_fedora/delegated_attribute.rb', line 5 def datastream_class @datastream_class end |
#dsid ⇒ Object
Returns the value of attribute dsid.
5 6 7 |
# File 'lib/active_fedora/delegated_attribute.rb', line 5 def dsid @dsid end |
#field ⇒ Object
Returns the value of attribute field.
5 6 7 |
# File 'lib/active_fedora/delegated_attribute.rb', line 5 def field @field end |
#multiple ⇒ Object
Returns the value of attribute multiple.
5 6 7 |
# File 'lib/active_fedora/delegated_attribute.rb', line 5 def multiple @multiple end |
Instance Method Details
#primary_solr_name ⇒ Object
Gives the primary solr name for a column. If there is more than one indexer on the field definition, it gives the first
16 17 18 19 20 21 22 23 |
# File 'lib/active_fedora/delegated_attribute.rb', line 16 def primary_solr_name @datastream ||= datastream_class.new if @datastream.respond_to?(:primary_solr_name) @datastream.primary_solr_name(field, dsid) else raise NoMethodError, "the datastream '#{datastream_class}' doesn't respond to 'primary_solr_name'" end end |
#reader(obj, *opts) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/active_fedora/delegated_attribute.rb', line 43 def reader(obj, *opts) ds = datastream_for_attribute(obj, dsid) if ds.kind_of?(ActiveFedora::RDFDatastream) read_rdf(ds) else read_om(ds, *opts) end end |
#type ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/active_fedora/delegated_attribute.rb', line 25 def type if datastream_class.respond_to?(:type) datastream_class.type(field) else raise NoMethodError, "the datastream '#{datastream_class}' doesn't respond to 'type'" end end |
#writer(obj, v) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/active_fedora/delegated_attribute.rb', line 33 def writer(obj, v) ds = datastream_for_attribute(obj, dsid) obj.mark_as_changed(field) if obj.value_has_changed?(field, v) if ds.kind_of?(ActiveFedora::RDFDatastream) write_rdf(ds, v) else write_om(ds, v) end end |