Sha256: ab9939d504f7606c3383f83875d65c0eb6196f386aa28bee07a0929651576547

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

module SPARQL; module Algebra
  class Operator

    ##
    # The SPARQL UPDATE `create` operator.
    #
    # This operation creates a graph in the Graph Store
    #
    # This is a no-op for RDF.rb implementations, unless the graph exists
    #
    # @example
    #   (create silent <graph>)
    #
    # @see https://www.w3.org/TR/sparql11-update/#create
    class Create < Operator
      include SPARQL::Algebra::Update

      NAME = [:create]

      ##
      # Executes this upate on the given `writable` graph or repository.
      #
      # @param  [RDF::Queryable] queryable
      #   the graph or repository to write
      # @param  [Hash{Symbol => Object}] options
      #   any additional keyword options
      # @option options [Boolean] debug
      #   Query execution debugging
      # @return [RDF::Queryable]
      #   Returns queryable.
      # @raise [IOError]
      #   If `from` does not exist, unless the `silent` operator is present
      # @see    https://www.w3.org/TR/sparql11-update/
      def execute(queryable, **options)
        debug(options) {"Create"}
        silent = operands.first == :silent
        operands.shift if silent

        iri = operands.first
        raise ArgumentError, "clear expected a single IRI" if operands.length != 1 || !iri.is_a?(RDF::URI)
        if queryable.has_graph?(iri)
          raise IOError, "create operation graph #{iri.to_ntriples} exists" unless silent
        end
        queryable
      end
    end # Create
  end # Operator
end; end # SPARQL::Algebra

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sparql-3.1.8 lib/sparql/algebra/operator/create.rb
sparql-3.1.7 lib/sparql/algebra/operator/create.rb
sparql-3.1.6 lib/sparql/algebra/operator/create.rb
sparql-3.1.5 lib/sparql/algebra/operator/create.rb
sparql-3.1.4 lib/sparql/algebra/operator/create.rb
sparql-3.1.3 lib/sparql/algebra/operator/create.rb
sparql-3.1.2 lib/sparql/algebra/operator/create.rb