Class: LD::Patch::Format

Inherits:
RDF::Format show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/ld-patch-a8edc852261e/lib/ld/patch/format.rb

Overview

LD::Patch format specification. Note that this format does not define any readers or writers.

Examples:

Obtaining an LD Patch format class

RDF::Format.for(:ldp)           #=> LD::Patch::Format
RDF::Format.for("etc/foaf.ldp")
RDF::Format.for(:file_name         => "etc/foaf.ldp")
RDF::Format.for(file_extension: "ldp")
RDF::Format.for(:content_type   => "text/ldpatch")

See Also:

Class Method Summary collapse

Methods inherited from RDF::Format

accept_type, accept_types, content_encoding, content_type, content_types, detect, each, file_extension, file_extensions, for, name, reader, reader_symbols, reader_types, require, symbols, uri, uris, writer, writer_symbols, writer_types

Class Method Details

.cli_commandsHash{Symbol => Lambda(Array, Hash)}

Hash of CLI commands appropriate for this format

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ld-patch-a8edc852261e/lib/ld/patch/format.rb', line 22

def self.cli_commands
  {
    patch: {
      description: "Patch the current graph using a patch file",
      help: "patch [--patch-input 'patch'] [--patch-file file]",
      control: :button,
      parse: true,
      lambda: -> (argv, opts) do
        opts[:patch_input] ||= case opts[:patch_file]
        when IO, StringIO then opts[:patch_file]
        else RDF::Util::File.open_file(opts[:patch_file]) {|f| f.read}
        end
        raise ArgumentError, "Patching requires a patch or reference to patch resource" unless opts[:patch_input]
        opts[:logger].info "Patch"
        patch = LD::Patch.parse(opts[:patch_input], base_uri: opts.fetch(:patch_file, "https://rubygems.org/gems/ld-patch"))
        opts[:messages][:reasoner] = {"S-Expression": [patch.to_sse]} if opts[:to_sxp]
        RDF::CLI.repository.query(patch)
      end,
      options: [
        RDF::CLI::Option.new(
          symbol: :patch_input,
          datatype: String,
          control: :none,
          on: ["--patch-input STRING"],
          description: "Patch in URI encoded format"
        ) {|v| CGI.decode(v)},
        RDF::CLI::Option.new(
          symbol: :patch_file,
          datatype: String,
          control: :url2,
          on: ["--patch-file URI"],
          description: "Patch file"
        ) {|v| RDF::URI(v)},
        RDF::CLI::Option.new(
          symbol: :to_sxp,
          datatype: String,
          control: :checkbox,
          on: ["--to-sxp"],
          description: "Instead of patching repository, display parsed patch as an S-Expression"
        ),
      ]
    }
  }
end

.to_symObject



67
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ld-patch-a8edc852261e/lib/ld/patch/format.rb', line 67

def self.to_sym; :ldpatch; end