version-one 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/version-one/asset.rb +63 -0
- data/lib/version-one/asset_ref.rb +17 -3
- data/lib/version-one/client.rb +1 -1
- data/lib/version-one/config.rb +8 -0
- data/lib/version-one/version.rb +1 -1
- data/lib/version-one/version.rb~ +1 -1
- metadata +2 -2
data/lib/version-one/asset.rb
CHANGED
@@ -160,6 +160,69 @@ module VersionOne
|
|
160
160
|
raise
|
161
161
|
end
|
162
162
|
|
163
|
+
def reply(msg)
|
164
|
+
self.class.reply_to(self, msg)
|
165
|
+
end
|
166
|
+
|
167
|
+
def self.reply_to(asset, msg)
|
168
|
+
asset_id = case asset
|
169
|
+
when Asset
|
170
|
+
asset.id
|
171
|
+
when String
|
172
|
+
asset
|
173
|
+
else
|
174
|
+
raise ArgumentError, 'Invalid asset argument'
|
175
|
+
end
|
176
|
+
|
177
|
+
raise ArgumentError, 'Cannot reply to this asset type' unless asset_id.match(/^Expression\:\d+$/)
|
178
|
+
|
179
|
+
reply = VersionOne::Expression.new(
|
180
|
+
content: msg,
|
181
|
+
in_reply_to: AssetRef.new(id: asset_id)
|
182
|
+
)
|
183
|
+
|
184
|
+
reply.save!
|
185
|
+
end
|
186
|
+
|
187
|
+
def comments(options={})
|
188
|
+
deep = options.key?(:deep) ? options[:deep] : true
|
189
|
+
|
190
|
+
query = VersionOne::Query.new('Expression').select(*%w{Author.Name Author.Email AuthoredAt Mentions InReplyTo Replies Content})
|
191
|
+
where = "Mentions='#{self.id}'"
|
192
|
+
if deep
|
193
|
+
where = "(#{where})|(InReplyTo.Mentions='#{self.id}')"
|
194
|
+
end
|
195
|
+
|
196
|
+
results = query.where(where).all
|
197
|
+
|
198
|
+
# Move reply information to the corresponding
|
199
|
+
# parent conversation
|
200
|
+
if deep
|
201
|
+
comments_by_id = results.index_by(&:id)
|
202
|
+
|
203
|
+
replies = results.select{|c| c.in_reply_to && comments_by_id.key?(c.in_reply_to.id)}
|
204
|
+
replies_by_id = replies.index_by(&:id)
|
205
|
+
|
206
|
+
results.map do |c|
|
207
|
+
if replies_by_id.key?(c.id)
|
208
|
+
nil
|
209
|
+
elsif c.replies.nil?
|
210
|
+
c
|
211
|
+
else
|
212
|
+
c.replies.each do |ref|
|
213
|
+
reply = replies_by_id[ref.id]
|
214
|
+
ref.set(reply) if reply
|
215
|
+
end
|
216
|
+
c
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
results.compact!
|
221
|
+
end
|
222
|
+
|
223
|
+
results
|
224
|
+
end
|
225
|
+
|
163
226
|
def exec(op_name, options={})
|
164
227
|
client = options[:client] || VersionOne::Client.new
|
165
228
|
client.post(href + "?op=#{op_name}")
|
@@ -10,11 +10,14 @@ module VersionOne
|
|
10
10
|
@asset = xml_or_asset
|
11
11
|
@id = @asset.id
|
12
12
|
@href = @asset.href
|
13
|
+
when Hash
|
14
|
+
@id = xml_or_asset[:id]
|
15
|
+
@href = xml_or_asset[:href]
|
13
16
|
else
|
14
17
|
@href = xml_or_asset.attributes['href']
|
15
18
|
@id = xml_or_asset.attributes['idref']
|
16
19
|
end
|
17
|
-
raise ArgumentError, "Could not get id and href" unless @id
|
20
|
+
raise ArgumentError, "Could not get id and href" unless @id || @href
|
18
21
|
end
|
19
22
|
|
20
23
|
def self.for(x)
|
@@ -25,14 +28,25 @@ module VersionOne
|
|
25
28
|
@asset ||= get_asset(*fields)
|
26
29
|
end
|
27
30
|
|
31
|
+
def set(asset)
|
32
|
+
case
|
33
|
+
when !asset.is_a?(VersionOne::Asset)
|
34
|
+
raise ArgumentError, "Parameter must be a VersionOne asset"
|
35
|
+
when asset.id == @id
|
36
|
+
@asset = asset
|
37
|
+
else
|
38
|
+
raise ArgumentError, "Asset does not match reference"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
28
42
|
def inspect
|
29
43
|
"#<AssetRef:#{@href}>"
|
30
44
|
end
|
31
45
|
|
32
46
|
def to_xml
|
33
47
|
xml = XML::Node.new('Asset')
|
34
|
-
xml.attributes['href'] = @href
|
35
|
-
xml.attributes['idref'] = @id
|
48
|
+
xml.attributes['href'] = @href if @href
|
49
|
+
xml.attributes['idref'] = @id if @id
|
36
50
|
xml
|
37
51
|
end
|
38
52
|
|
data/lib/version-one/client.rb
CHANGED
data/lib/version-one/config.rb
CHANGED
data/lib/version-one/version.rb
CHANGED
data/lib/version-one/version.rb~
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: version-one
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: libxml-ruby
|