Module: Spira::Type
- Includes:
- RDF
- Included in:
- Spira::Types::Any, Spira::Types::AnyURI, Spira::Types::Boolean, Spira::Types::Date, Spira::Types::DateTime, Spira::Types::Decimal, Spira::Types::Double, Spira::Types::Float, Spira::Types::GYear, Spira::Types::Int, Spira::Types::Integer, Spira::Types::Long, Spira::Types::Native, Spira::Types::NegativeInteger, Spira::Types::NonNegativeInteger, Spira::Types::NonPositiveInteger, Spira::Types::PositiveInteger, Spira::Types::String, Spira::Types::Time, Spira::Types::URI
- Defined in:
- lib/spira/type.rb
Overview
Spira::Type can be included by classes to create new property types for Spira. These types are responsible for serialization a Ruby value into an ‘RDF::Value`, and deserialization of an `RDF::Value` into a Ruby value.
A simple example:
class Integer
include Spira::Type
def self.unserialize(value)
value.object
end
def self.serialize(value)
RDF::Literal.new(value)
end
register_alias XSD.integer
end
This example will serialize and deserialize integers. It’s included with Spira by default. It allows either of the following forms to declare an integer property on a Spira resource:
property :age, predicate: RDF::Vocab::FOAF.age, type: Integer
property :age, predicate: RDF::Vocab::FOAF.age, type: RDF::XSD.integer
‘Spira::Type`s include the RDF namespace and thus have all of the base RDF vocabularies available to them without the `RDF::` prefix.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(child) ⇒ Object
Make the DSL available to a child class.
Class Method Details
.included(child) ⇒ Object
Make the DSL available to a child class.
43 44 45 46 |
# File 'lib/spira/type.rb', line 43 def self.included(child) child.extend(ClassMethods) Spira.type_alias(child,child) end |