• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-rdf / rdf / 5194667710

07 Jun 2023 12:30AM UTC coverage: 91.808% (+0.1%) from 91.682%
5194667710

push

github

gkellogg
More ruby warning fixes.

4886 of 5322 relevant lines covered (91.81%)

16981.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.81
/lib/rdf.rb
1
require 'stringio'
2✔
2
require 'bigdecimal'
2✔
3
require 'date'
2✔
4
require 'time'
2✔
5
require "ostruct"
2✔
6

7
require 'rdf/version'
2✔
8

9
module RDF
2✔
10
  # RDF mixins
11
  autoload :Countable,         'rdf/mixin/countable'
2✔
12
  autoload :Durable,           'rdf/mixin/durable'
2✔
13
  autoload :Enumerable,        'rdf/mixin/enumerable'
2✔
14
  autoload :Indexable,         'rdf/mixin/indexable'
2✔
15
  autoload :Mutable,           'rdf/mixin/mutable'
2✔
16
  autoload :Queryable,         'rdf/mixin/queryable'
2✔
17
  autoload :Readable,          'rdf/mixin/readable'
2✔
18
  autoload :TypeCheck,         'rdf/mixin/type_check'
2✔
19
  autoload :Transactable,      'rdf/mixin/transactable'
2✔
20
  autoload :Writable,          'rdf/mixin/writable'
2✔
21

22
  # RDF objects
23
  autoload :Graph,             'rdf/model/graph'
2✔
24
  autoload :IRI,               'rdf/model/uri'
2✔
25
  autoload :Literal,           'rdf/model/literal'
2✔
26
  autoload :Node,              'rdf/model/node'
2✔
27
  autoload :Resource,          'rdf/model/resource'
2✔
28
  autoload :Statement,         'rdf/model/statement'
2✔
29
  autoload :URI,               'rdf/model/uri'
2✔
30
  autoload :Value,             'rdf/model/value'
2✔
31
  autoload :Term,              'rdf/model/term'
2✔
32

33
  # RDF collections
34
  autoload :List,              'rdf/model/list'
2✔
35

36
  # RDF serialization
37
  autoload :Format,            'rdf/format'
2✔
38
  autoload :Reader,            'rdf/reader'
2✔
39
  autoload :ReaderError,       'rdf/reader'
2✔
40
  autoload :Writer,            'rdf/writer'
2✔
41
  autoload :WriterError,       'rdf/writer'
2✔
42

43
  # RDF serialization formats
44
  autoload :NTriples,          'rdf/ntriples'
2✔
45
  autoload :NQuads,            'rdf/nquads'
2✔
46

47
  # RDF storage
48
  autoload :Changeset,         'rdf/changeset'
2✔
49
  autoload :Dataset,           'rdf/model/dataset'
2✔
50
  autoload :Repository,        'rdf/repository'
2✔
51
  autoload :Transaction,       'rdf/transaction'
2✔
52

53
  # RDF querying
54
  autoload :Query,             'rdf/query'
2✔
55

56
  # RDF vocabularies
57
  autoload :Vocabulary,        'rdf/vocabulary'
2✔
58
  autoload :StrictVocabulary,  'rdf/vocabulary'
2✔
59

60
  VOCABS = {
61
    owl: {uri: "http://www.w3.org/2002/07/owl#", class_name: "OWL"},
2✔
62
    rdfs: {uri: "http://www.w3.org/2000/01/rdf-schema#", class_name: "RDFS"},
63
    rdfv: {uri: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", class_name: "RDFV"},
64
    xsd: {uri: "http://www.w3.org/2001/XMLSchema#", class_name: "XSD"},
65
  }
66

67
  # Autoload vocabularies
68
  VOCABS.each do |id, params|
2✔
69
    v = (params[:class_name] ||= id.to_s.upcase).to_sym
8✔
70
    autoload v, File.expand_path("../rdf/vocab/#{id}", __FILE__)
8✔
71
  end
72

73
  # Utilities
74
  autoload :Util,        'rdf/util'
2✔
75

76
  # CLI
77
  autoload :CLI,         'rdf/cli'
2✔
78

79
  ##
80
  # Configuration, used open for configuring constants used within the codebase.
81
  #
82
  # @example set default cache size to be at most 10,000 entries
83
  #
84
  #   RDF.config.cache_size = 10_000
85
  #
86
  # @example set cache size for interned URIs to 5,000 entries
87
  #
88
  #   RDF.config.uri_cache_size = 5_000
89
  #
90
  # Defaults:
91
  #   * `cache_size`: -1
92
  #   * `uri_cache_size`: `cache_size`
93
  #   * `node_cache_size`: `cache_size`
94
  #
95
  # @note cache configurations must be set before initial use, when the caches are allocated.
96
  # @see RDF::Util::Cache.new
97
  # @return [Object]
98
  def self.config
2✔
99
    @config ||= OpenStruct.new(cache_size: -1, uri_cache_size: nil, node_cache_size: nil)
112✔
100
  end
101

102
  ##
103
  # Alias for `RDF::Resource.new`.
104
  #
105
  # @param (see RDF::Resource#initialize)
106
  # @return [RDF::Resource]
107
  def self.Resource(*args)
2✔
108
    Resource.new(*args)
×
109
  end
110

111
  ##
112
  # Alias for `RDF::Node.new`.
113
  #
114
  # @param (see RDF::Node#initialize)
115
  # @return [RDF::Node]
116
  def self.Node(*args)
2✔
117
    Node.new(*args)
160✔
118
  end
119

120
  ##
121
  # Cast to a URI. If already a URI, return the passed argument.
122
  #
123
  # @param (see RDF::URI#initialize)
124
  # @return [RDF::URI]
125
  def self.URI(*args)
2✔
126
    if args.first.respond_to?(:to_uri)
207,734✔
127
      args.first.to_uri
29,288✔
128
    elsif args.first.is_a?(Hash)
178,446✔
129
      URI.new(**args.first)
8✔
130
    else
131
      opts = args.last.is_a?(Hash) ? args.pop : {}
178,438✔
132
      URI.new(*args, **opts)
178,438✔
133
    end
134
  end
135

136
  ##
137
  # Alias for `RDF::Literal.new`.
138
  #
139
  # @param (see RDF::Literal#initialize)
140
  # @return [RDF::Literal]
141
  def self.Literal(literal, **options)
2✔
142
    case literal
4,200✔
143
      when RDF::Literal then literal
80✔
144
      else Literal.new(literal, **options)
4,120✔
145
    end
146
  end
147

148
  ##
149
  # Alias for `RDF::Graph.new`.
150
  #
151
  # @param (see RDF::Graph#initialize)
152
  # @return [RDF::Graph]
153
  def self.Graph(**options, &block)
2✔
154
    Graph.new(**options, &block)
2✔
155
  end
156

157
  ##
158
  # @overload List()
159
  #   @return [RDF::URI] returns the IRI for `rdf:List`
160
  #
161
  # @overload List(*args)
162
  #   @param (see RDF::List#[])
163
  #   @return [RDF::List]
164
  #
165
  # @overload List(array)
166
  #   @param [Array] array
167
  #   @return [RDF::List]
168
  #
169
  # @overload List(list)
170
  #   @param [RDF::List] list
171
  #   @return [RDF::List] returns itself
172
  def self.List(*args)
2✔
173
    case
174
    when args.empty?
176✔
175
      RDF[:List]
158✔
176
    when args.length == 1 && args.first.is_a?(RDF::List)
177
      args.first
2✔
178
    when args.length == 1 && args.first.is_a?(Array)
179
      List[*args.first]
4✔
180
    else
181
      List[*args]
12✔
182
    end
183
  end
184

185
  ##
186
  # @overload Statement()
187
  #   @return [RDF::URI] returns the IRI for `rdf:Statement`
188
  #
189
  # @overload Statement(**options)
190
  #   @param  [Hash{Symbol => Object}] options
191
  #   @option options [RDF::Resource]  :subject   (nil)
192
  #   @option options [RDF::URI]       :predicate (nil)
193
  #   @option options [RDF::Term]      :object    (nil)
194
  #   @option options [RDF::Resource]  :graph_name   (nil)
195
  #     Note, a graph_name MUST be an IRI or BNode.
196
  #   @return [RDF::Statement]
197
  #
198
  # @overload Statement(subject, predicate, object, **options)
199
  #   @param  [RDF::Resource]          subject
200
  #   @param  [RDF::URI]               predicate
201
  #   @param  [RDF::Term]              object
202
  #   @param  [Hash{Symbol => Object}] options
203
  #   @option options [RDF::Resource]  :graph_name   (nil)
204
  #   @return [RDF::Statement]
205
  #
206
  def self.Statement(*args, **options)
2✔
207
    if args.empty? && options.empty?
9,044✔
208
      RDF[:Statement]
×
209
    else
210
      Statement.new(*args, **options)
9,044✔
211
    end
212
  end
213

214
  ##
215
  # Alias for `RDF::Vocabulary.create`.
216
  #
217
  # @param (see RDF::Vocabulary#initialize)
218
  # @return [Class]
219
  def self.Vocabulary(uri)
2✔
220
    Vocabulary.create(uri)
22✔
221
  end
222

223
  ##
224
  # Alias for `RDF::StrictVocabulary.create`.
225
  #
226
  # @param (see RDF::Vocabulary#initialize)
227
  # @return [Class]
228
  def self.StrictVocabulary(uri)
2✔
229
    StrictVocabulary.create(uri)
144✔
230
  end
231

232
  ##
233
  # @return [#to_s] property
234
  # @return [URI]
235
  def self.[](property)
2✔
236
    property.to_s.match?(%r{_\d+}) ? RDF::URI("#{to_uri}#{property}") : RDF::RDFV[property]
988✔
237
  end
238

239
  ##
240
  # Return an enumerator over {RDF::Statement} defined for this vocabulary.
241
  # @return [RDF::Enumerable::Enumerator]
242
  # @see    Object#enum_for
243
  def self.enum_for(method = :each_statement, *args)
2✔
244
    # Ensure that enumerators are, themselves, queryable
245
    Enumerable::Enumerator.new do |yielder|
6✔
246
      RDF::RDFV.send(method, *args) {|*y| yielder << (y.length > 1 ? y : y.first)}
840✔
247
    end
248
  end
249
  class << self
2✔
250
    alias_method :to_enum, :enum_for
2✔
251
  end
252

253
  ##
254
  # respond to module or RDFV
255
  def self.respond_to?(method, include_all = false)
2✔
256
    super || RDF::RDFV.respond_to?(method, include_all)
34✔
257
  end
258

259
  RDF_N_REGEXP = %r{_\d+}.freeze
2✔
260

261
  ##
262
  # Delegate other methods to RDF::RDFV
263
  def self.method_missing(property, *args, &block)
2✔
264
    if args.empty?
341,616✔
265
      # Special-case rdf:_n for all integers
266
      RDF_N_REGEXP.match?(property) ? RDF::URI("#{to_uri}#{property}") : RDF::RDFV.send(property)
341,616✔
267
    else
268
      super
×
269
    end
270
  end
271
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc