Skip to content

Commit 33ca366

Browse files
doriantaylorgkellogg
authored andcommitted
fixes to docs etc
1 parent a045087 commit 33ca366

4 files changed

Lines changed: 33 additions & 25 deletions

File tree

lib/rdf/changeset.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def initialize(insert: [], delete: [], &block)
8787
end
8888

8989
##
90-
# Returns +false+ to indicate that this changeset is append-only.
90+
# Returns `false` to indicate that this changeset is append-only.
9191
#
92-
# Changesets do not support the +RDF::Enumerable+ protocol directly.
92+
# Changesets do not support the `RDF::Enumerable` protocol directly.
9393
# To enumerate the RDF statements to be inserted or deleted, use the
9494
# {RDF::Changeset#inserts} and {RDF::Changeset#deletes} accessors.
9595
#
@@ -100,7 +100,7 @@ def readable?
100100
end
101101

102102
##
103-
# Returns +false+ to indicate that this changeset _itself_ is not writable.
103+
# Returns `false` as changesets are not {RDF::Writable}.
104104
#
105105
# @return [Boolean]
106106
# @see RDF::Writable#writable?
@@ -109,7 +109,7 @@ def writable?
109109
end
110110

111111
##
112-
# Returns +false+ to indicate that this changeset _itself_ is not mutable.
112+
# Returns `false` as changesets are not {RDF::Mutable}.
113113
#
114114
# @return [Boolean]
115115
# @see RDF::Mutable#mutable?
@@ -130,7 +130,7 @@ def apply(mutable, **options)
130130
end
131131

132132
##
133-
# @return [Boolean] +true+ iff inserts and deletes are both empty
133+
# @return [Boolean] `true` iff inserts and deletes are both empty
134134
def empty?
135135
deletes.empty? && inserts.empty?
136136
end
@@ -146,29 +146,29 @@ def inspect
146146

147147
##
148148
# Outputs a developer-friendly representation of this changeset to
149-
# +$stderr+.
149+
# `$stderr`.
150150
#
151151
# @return [void]
152152
def inspect!
153153
$stderr.puts(self.inspect)
154154
end
155155

156156
##
157-
# Returns the sum of both the +inserts+ and +deletes+ counts.
157+
# Returns the sum of both the `inserts` and `deletes` counts.
158158
#
159159
# @return [Integer]
160160
def count
161161
inserts.count + deletes.count
162162
end
163163

164-
# Append statements to +inserts+. Statements _should_ be constant
164+
# Append statements to `inserts`. Statements _should_ be constant
165165
# as variable statements will at best be ignored or at worst raise
166166
# an error when applied.
167167
#
168-
# @param statements [Enumerable, # RDF::Statement] Some statements
168+
# @param statements [Enumerable, RDF::Statement] Some statements
169169
# @return [self]
170170
def insert(*statements)
171-
process_statements(statements) do |stmts|
171+
coerce_statements(statements) do |stmts|
172172
append_statements :inserts, stmts
173173
end
174174

@@ -177,14 +177,14 @@ def insert(*statements)
177177
alias_method :insert!, :insert
178178
alias_method :<<, :insert
179179

180-
# Append statements to +deletes+. Statements _may_ contain
180+
# Append statements to `deletes`. Statements _may_ contain
181181
# variables, although support will depend on the {RDF::Mutable}
182182
# target.
183183
#
184184
# @param statements [Enumerable, RDF::Statement] Some statements
185185
# @return [self]
186186
def delete(*statements)
187-
process_statements(statements) do |stmts|
187+
coerce_statements(statements) do |stmts|
188188
append_statements :deletes, stmts
189189
end
190190

@@ -196,8 +196,8 @@ def delete(*statements)
196196
private
197197

198198
##
199-
# Append statements to the appropriate target. This is a crappy
200-
# little shim to go in between the other shim and the target.
199+
# Append statements to the appropriate target. This is a little
200+
# shim to go in between the other shim and the target.
201201
#
202202
# @param target [Symbol] the method to send
203203
# @param arg [Enumerable, RDF::Statement]

lib/rdf/mixin/mutable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def update(*statements)
155155
def delete(*statements)
156156
raise TypeError.new("#{self} is immutable") if immutable?
157157

158-
process_statements(statements, query: true, constant: true) do |value|
158+
coerce_statements(statements, query: true, constant: true) do |value|
159159
delete_statements(value)
160160
end
161161

lib/rdf/mixin/writable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def <<(data)
5959
# @param [Enumerable<RDF::Statement>] statements
6060
# @return [self]
6161
def insert(*statements)
62-
process_statements(statements) { |value| insert_statements value }
62+
coerce_statements(statements) { |value| insert_statements value }
6363

6464
return self
6565
end

lib/rdf/util/coercions.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
module RDF
23
module Util
34
module Coercions
@@ -6,20 +7,29 @@ module Coercions
67
# preprocessor that is used in e.g. {RDF::Writable#insert} and
78
# {RDF::Mutable#delete}.
89

10+
protected
11+
912
##
10-
# Coerce a set of arguments into {RDF::Statement} objects and then
11-
# operate over them with a block.
13+
# Coerce an array of arguments into {RDF::Statement}, or
14+
# {RDF::Enumerable} and then yield to a block. Note that this
15+
# code was amalgamated from that which was sandwiched around
16+
# both {RDF::Writable#insert_statements} and
17+
# {RDF::Mutable#delete_statements}. The parameters `query` and
18+
# `constant` are therefore present to handle the conditions
19+
# where the statements contain wildcards and what to do about
20+
# them.
1221
#
1322
# @example
14-
# process_statements(statements) { |value| do_something(value) }
23+
# coerce_statements(statements) { |value| do_something(value) }
1524
#
1625
# @param statements [#map] The arbitrary-ish input to be manipulated
17-
# @param query [false, true] Whether to call +query+ before the block
26+
# @param query [false, true] Whether to call `query` before the block
27+
# (as expected by {Mutable#delete_statements})
1828
# @param constant [false, true] Whether to test if the statements
19-
# are constant
29+
# are constant (as expected by {Mutable#delete_statements})
2030
# @yield [RDF::Statement, RDF::Enumerable]
2131
# @return statements
22-
def process_statements(statements, query: false, constant: false, &block)
32+
def coerce_statements(statements, query: false, constant: false, &block)
2333
raise ArgumentError, 'expecting a block' unless block_given?
2434

2535
statements = statements.map do |value|
@@ -32,7 +42,7 @@ def process_statements(statements, query: false, constant: false, &block)
3242
statement
3343
when query
3444
# XXX note that this only makes sense when the module is include()d
35-
block.call(query(value))
45+
block.call(self.query(value))
3646
nil
3747
else
3848
raise ArgumentError, "Not a valid statement: #{value.inspect}"
@@ -45,8 +55,6 @@ def process_statements(statements, query: false, constant: false, &block)
4555
statements
4656
end
4757

48-
# so you can include or call
49-
extend self
5058
end
5159
end
5260
end

0 commit comments

Comments
 (0)