Class: Zizia::MetadataMapper
- Inherits:
-
Object
- Object
- Zizia::MetadataMapper
- Defined in:
- lib/zizia/metadata_mapper.rb
Overview
A null/base mapper that maps no fields.
Real mapper implementations need to provide ‘#fields`, enumerating over `Symbols` that represent the fields on the target object (e.g. an `ActiveFedora::Base`/`Hyrax::WorkBehavior`) that the mapper can handle. For each field in `#fields`, the mapper must respond to a matching method (i.e. `:title` => `#title`), and return the value(s) that should be set to the target’s attributes upon mapping.
To ease the implementation of field methods, this base class provides a ‘#method_missing` that forwards missing method names to a `#map_field` method. `#map_field` can be implemented to provide a generalized field mapping when a common pattern will be used for many methods. Callers should avoid relying on this protected method directly, since mappers may implement individual field methods in any other way (e.g. `def title; end`) to route around `#map_field`. Implementations are also free to override `#method_missing` if desired.
Mappers generally operate over some input ‘#metadata`. Example metadata types that mappers could be implemented over include `Hash`, `CSV`, `XML`, `RDF::Graph`, etc…; mappers are free to interpret or ignore the contents of their underlying metadata data structures at their leisure. Values for fields are /usually/ derived from the `#metadata`, but can also be generated from complex logic or even hard-coded.
Direct Known Subclasses
Instance Attribute Summary collapse
Instance Method Summary collapse
- #field?(name) ⇒ Boolean
-
#fields ⇒ Enumerable<Symbol>
The fields the mapper can process.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
62 63 64 65 |
# File 'lib/zizia/metadata_mapper.rb', line 62 def method_missing(method_name, *args, &block) return map_field(method_name) if fields.include?(method_name) super end |
Instance Attribute Details
#metadata ⇒ Object
46 47 48 |
# File 'lib/zizia/metadata_mapper.rb', line 46 def @metadata end |
Instance Method Details
#field?(name) ⇒ Boolean
52 53 54 |
# File 'lib/zizia/metadata_mapper.rb', line 52 def field?(name) fields.include?(name) end |
#fields ⇒ Enumerable<Symbol>
Returns The fields the mapper can process.
58 59 60 |
# File 'lib/zizia/metadata_mapper.rb', line 58 def fields [] end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
67 68 69 |
# File 'lib/zizia/metadata_mapper.rb', line 67 def respond_to_missing?(method_name, include_private = false) field?(method_name) || super end |