Class: Gearbox::Types::Any

Inherits:
Object
  • Object
show all
Includes:
Gearbox::Type
Defined in:
lib/gearbox/types/any.rb

Overview

This class does its best to serialize or unserialize RDF values into Ruby values and vice versa using RDF.rb’s built-in helpers for ‘RDF::Literal`s. Its behavior is defined as ’What ‘RDF::Literal` does’ for a given value.

Class Method Summary collapse

Methods included from Gearbox::Type

included

Class Method Details

.serialize(value) ⇒ Object

Raises:

  • (TypeError)


18
19
20
21
# File 'lib/gearbox/types/any.rb', line 18

def self.serialize(value)
  raise TypeError, "Gearbox::Types::Any cannot serialize collections" if value.is_a?(Array)
  value.is_a?(RDF::Value) ? value : RDF::Literal.new(value)
end

.unserialize(value) ⇒ Object



14
15
16
# File 'lib/gearbox/types/any.rb', line 14

def self.unserialize(value)
  value.respond_to?(:object) ? value.object : value
end