Class: Valkyrie::ValueMapper
- Inherits:
-
Object
- Object
- Valkyrie::ValueMapper
- Defined in:
- lib/valkyrie/value_mapper.rb
Overview
ValueMapper is a way to handle coordinating extendable casting of values depending on what the value is. It’s used in many of the adapters in Valkyrie.
Typically a root node is defined as a sub-class ValueMapper to separate value mappers for a distinct purpose, but it’s not a requirement.
Direct Known Subclasses
Persistence::Fedora::Persister::ModelConverter::FedoraValue, Persistence::Fedora::Persister::ModelConverter::MappedFedoraValue, Persistence::Fedora::Persister::ModelConverter::NestedProperty, Persistence::Fedora::Persister::ModelConverter::OrderedMembers, Persistence::Fedora::Persister::ModelConverter::OrderedProperties, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::BooleanValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::CreatedAtValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::DateTimeValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::DenylistedValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::DifferentSubject, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::FedoraValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::FloatValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::IntegerValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::InternalModelValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::InternalURI, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::LiteralValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::MemberID, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::NestedValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::OrderedProperty, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::TimeValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::UpdatedAtValue, Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::ValkyrieIDValue, Persistence::Shared::JSONValueMapper::DateValue, Persistence::Shared::JSONValueMapper::EnumeratorValue, Persistence::Shared::JSONValueMapper::HashValue, Persistence::Shared::JSONValueMapper::IDValue, Persistence::Shared::JSONValueMapper::NestedRecord, Persistence::Shared::JSONValueMapper::PostgresValue, Persistence::Shared::JSONValueMapper::URIValue, Persistence::Solr::ModelConverter::BooleanPropertyValue, Persistence::Solr::ModelConverter::DateTimePropertyValue, Persistence::Solr::ModelConverter::EnumerableValue, Persistence::Solr::ModelConverter::FloatPropertyValue, Persistence::Solr::ModelConverter::IDPropertyValue, Persistence::Solr::ModelConverter::IntegerPropertyValue, Persistence::Solr::ModelConverter::LiteralPropertyValue, Persistence::Solr::ModelConverter::NestedObjectValue, Persistence::Solr::ModelConverter::SharedStringPropertyValue, Persistence::Solr::ModelConverter::SolrMapperValue, Persistence::Solr::ModelConverter::StringPropertyValue, Persistence::Solr::ModelConverter::URIPropertyValue, Persistence::Solr::ORMConverter::BooleanValue, Persistence::Solr::ORMConverter::DateTimeValue, Persistence::Solr::ORMConverter::EnumerableValue, Persistence::Solr::ORMConverter::FloatValue, Persistence::Solr::ORMConverter::IDValue, Persistence::Solr::ORMConverter::IntegerValue, Persistence::Solr::ORMConverter::NestedEnumerable, Persistence::Solr::ORMConverter::NestedResourceConverter, Persistence::Solr::ORMConverter::NestedResourceHash, Persistence::Solr::ORMConverter::NestedResourceID, Persistence::Solr::ORMConverter::NestedResourceLiteral, Persistence::Solr::ORMConverter::NestedResourceURI, Persistence::Solr::ORMConverter::NestedResourceValue, Persistence::Solr::ORMConverter::PropertyValue, Persistence::Solr::ORMConverter::RDFLiteralPropertyValue, Persistence::Solr::ORMConverter::SolrValue, Persistence::Solr::ORMConverter::URIValue
Class Attribute Summary collapse
-
.value_casters ⇒ Array<Valkyrie::ValueMapper>
Registered value casters.
Instance Attribute Summary collapse
-
#calling_mapper ⇒ Object
readonly
Returns the value of attribute calling_mapper.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.for(value) ⇒ Object
Find the value caster for a given value.
-
.handles?(_value) ⇒ Boolean
Test whether this caster handles a given value.
-
.register(value_caster) ⇒ Object
Register a value caster.
Instance Method Summary collapse
-
#initialize(value, calling_mapper) ⇒ ValueMapper
constructor
A new instance of ValueMapper.
-
#result ⇒ Object
Casted value.
Constructor Details
#initialize(value, calling_mapper) ⇒ ValueMapper
Returns a new instance of ValueMapper.
57 58 59 60 |
# File 'lib/valkyrie/value_mapper.rb', line 57 def initialize(value, calling_mapper) @value = value @calling_mapper = calling_mapper end |
Class Attribute Details
.value_casters ⇒ Array<Valkyrie::ValueMapper>
Returns Registered value casters.
33 34 35 |
# File 'lib/valkyrie/value_mapper.rb', line 33 def self.value_casters @value_casters ||= [] end |
Instance Attribute Details
#calling_mapper ⇒ Object (readonly)
Returns the value of attribute calling_mapper.
56 57 58 |
# File 'lib/valkyrie/value_mapper.rb', line 56 def calling_mapper @calling_mapper end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
56 57 58 |
# File 'lib/valkyrie/value_mapper.rb', line 56 def value @value end |
Class Method Details
.for(value) ⇒ Object
Find the value caster for a given value.
43 44 45 46 47 |
# File 'lib/valkyrie/value_mapper.rb', line 43 def self.for(value) (value_casters + [self]).find do |value_caster| value_caster.handles?(value) end.new(value, self) end |
.handles?(_value) ⇒ Boolean
Test whether this caster handles a given value.
52 53 54 |
# File 'lib/valkyrie/value_mapper.rb', line 52 def self.handles?(_value) true end |
.register(value_caster) ⇒ Object
Register a value caster.
28 29 30 |
# File 'lib/valkyrie/value_mapper.rb', line 28 def self.register(value_caster) self.value_casters += [value_caster] end |
Instance Method Details
#result ⇒ Object
Returns Casted value.
63 64 65 |
# File 'lib/valkyrie/value_mapper.rb', line 63 def result value end |