Class: RDF::URI

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/ext/uri.rb

Instance Method Summary collapse

Instance Method Details

#as(klass, *args) {|self| ... } ⇒ Klass

Create a projection of this URI as the given Spira::Resource class. Equivalent to klass.for(self, *args)

Examples:

Instantiating a URI as a Spira Resource

RDF::URI('http://example.org/person/bob').as(Person)

Parameters:

  • klass (Class)
  • args (*Any)

    Any arguments to pass to klass.for

Yields:

  • (self)

    Executes a given block and calls #save!

Yield Parameters:

  • self (self)

    The newly created instance

Returns:

  • (Klass)

    An instance of klass

Raises:

  • (ArgumentError)


14
15
16
17
# File 'lib/rdf/ext/uri.rb', line 14

def as(klass, *args, &block)
  raise ArgumentError, "#{klass} is not a Spira resource" unless klass.is_a?(Class) && klass.ancestors.include?(Spira::Base)
  klass.for(self, *args, &block)
end