Class: ShEx::Format
- Inherits:
-
RDF::Format
- Object
- RDF::Format
- ShEx::Format
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/format.rb
Overview
ShEx format specification. Note that this format does not define any readers or writers.
Class Method Summary collapse
-
.cli_commands ⇒ Hash{Symbol => Lambda(Array, Hash)}
Hash of CLI commands appropriate for this format.
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, to_sym, uri, uris, writer, writer_symbols, writer_types
Class Method Details
.cli_commands ⇒ Hash{Symbol => Lambda(Array, Hash)}
Hash of CLI commands appropriate for this format
20 21 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/format.rb', line 20 def self.cli_commands { shex: { description: "Validate repository given shape", help: "shex [--shape Resource] [--focus Resource] [--schema-input STRING] [--schema STRING] file", parse: true, lambda: -> (argv, **) do [:schema_input] ||= case [:schema] when IO, StringIO then [:schema] else RDF::Util::File.open_file([:schema]) {|f| f.read} end raise ArgumentError, "Shape matching requires a schema or reference to schema resource" unless [:schema_input] raise ArgumentError, "Shape matching requires a focus node" unless [:focus] format = [:schema].to_s.end_with?('json') ? 'shexj' : 'shexc' shex = ShEx.parse([:schema_input], format: format, **) if [:to_sxp] || [:to_json] [:messages][:shex] = {} [:messages][:shex].merge!({"S-Expression": [SXP::Generator.string(shex.to_sxp_bin)]}) if [:to_sxp] [:messages][:shex].merge!({ShExJ: [shex.to_json(JSON::LD::JSON_STATE)]}) if [:to_json] else focus = .delete(:focus) shape = .delete(:shape) map = shape ? {focus => shape} : {} begin res = shex.execute(RDF::CLI.repository, map, focus: focus, **) [:messages][:shex] = { result: ["Satisfied shape."], detail: [SXP::Generator.string(res.to_sxp_bin)] } rescue ShEx::NotSatisfied => e [:logger].error e.to_s [:messages][:shex] = { result: ["Did not satisfied shape."], detail: [SXP::Generator.stringe.expression] } raise end end end, options: [ RDF::CLI::Option.new( symbol: :focus, datatype: String, control: :text, use: :required, on: ["--focus Resource"], description: "Focus node within repository" ) {|v| RDF::URI(v)}, RDF::CLI::Option.new( symbol: :shape, datatype: String, control: :text, use: :optional, on: ["--shape URI"], description: "Shape identifier within ShEx schema" ) {|v| RDF::URI(v)}, RDF::CLI::Option.new( symbol: :schema_input, datatype: String, control: :none, on: ["--schema-input STRING"], description: "ShEx schema in URI encoded format" ) {|v| URI.decode(v)}, RDF::CLI::Option.new( symbol: :schema, datatype: String, control: :url2, on: ["--schema URI"], description: "ShEx schema location" ) {|v| RDF::URI(v)}, RDF::CLI::Option.new( symbol: :to_json, datatype: String, control: :checkbox, on: ["--to-json"], description: "Display parsed schema as ShExJ" ), RDF::CLI::Option.new( symbol: :to_sxp, datatype: String, control: :checkbox, on: ["--to-sxp"], description: "Display parsed schema as an S-Expression" ), ] } } end |