Sha256: efa96d594567032e42b43d00afc7c87838ee2a10479c5566320f671305aa59f6

Contents?: true

Size: 1.4 KB

Versions: 13

Compression:

Stored size: 1.4 KB

Contents

module RDF
  class URI
    ##
    # Create a projection of this URI as the given Spira::Resource class.
    # Equivalent to `klass.for(self, *args)`
    #
    # @example Instantiating a URI as a Spira Resource
    #     RDF::URI('http://example.org/person/bob').as(Person)
    # @param [Class] klass
    # @param [*Any] args Any arguments to pass to klass.for
    # @yield [self] Executes a given block and calls `#save!`
    # @yieldparam [self] self The newly created instance
    # @return [Klass] An instance of klass
    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
  end

  class Node
    ##
    # Create a projection of this Node as the given Spira::Resource class.
    # Equivalent to `klass.for(self, *args)`
    #
    # @example Instantiating a blank node as a Spira Resource
    #     RDF::Node.new.as(Person)
    # @param [Class] klass
    # @param [*Any] args Any arguments to pass to klass.for
    # @yield [self] Executes a given block and calls `#save!`
    # @yieldparam [self] self The newly created instance
    # @return [Klass] An instance of klass
    def as(klass, *args)
      raise ArgumentError, "#{klass} is not a Spira resource" unless klass.is_a?(Class) && klass.ancestors.include?(Spira::Base)
      klass.for(self, *args)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spira-3.3.0 lib/rdf/ext/uri.rb
spira-3.2.0 lib/rdf/ext/uri.rb
spira-3.1.1 lib/rdf/ext/uri.rb
spira-3.1.0 lib/rdf/ext/uri.rb
spira-3.0.0 lib/rdf/ext/uri.rb
spira-2.1.0 lib/rdf/ext/uri.rb
spira-2.0.2 lib/rdf/ext/uri.rb
spira-2.0.1 lib/rdf/ext/uri.rb
spira-2.0.0 lib/rdf/ext/uri.rb
spira-1.1.1 lib/rdf/ext/uri.rb
spira-0.7.1 lib/rdf/ext/uri.rb
spira-0.7 lib/rdf/ext/uri.rb
spira-0.5.0 lib/rdf/ext/uri.rb