Module: Gearbox::Type
- Includes:
- RDF
- Included in:
- Gearbox::Types::Any, Gearbox::Types::Boolean, Gearbox::Types::Date, Gearbox::Types::Decimal, Gearbox::Types::Float, Gearbox::Types::Integer, Gearbox::Types::Native, Gearbox::Types::String, Gearbox::Types::URI
- Defined in:
- lib/gearbox/type.rb
Overview
This was taken wholesale from Spira. I think Ben did a great job with that. I have nothing to add or detract from his good work.
Gearbox::Type can be included by classes to create new property types for Gearbox. 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 Gearbox::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 Gearbox by default. It allows either of the following forms to declare an integer property on a Gearbox resource:
property :age, :predicate => FOAF.age, :type => Integer
property :age, :predicate => FOAF.age, :type => XSD.integer
‘Gearbox::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.
46 47 48 49 |
# File 'lib/gearbox/type.rb', line 46 def self.included(child) child.extend(ClassMethods) Gearbox.type_alias(child,child) end |