omf_sfa 0.1.5 → 0.2.0
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/omf-sfa/resource/oproperty.rb +22 -14
- data/lib/omf-sfa/resource/oresource.rb +16 -10
- data/lib/omf-sfa/version.rb +1 -1
- metadata +2 -2
@@ -120,8 +120,6 @@ module OMF::SFA::Resource
|
|
120
120
|
q = "SELECT r.id, r.type, r.uuid, r.name FROM #{from.join(', ')} WHERE #{where.join(' AND ')};"
|
121
121
|
debug "prop_all q: #{q}"
|
122
122
|
res = repository(:default).adapter.select(q)
|
123
|
-
puts OMF::JobService::Resource::Job
|
124
|
-
|
125
123
|
ores = res.map do |qr|
|
126
124
|
if resource_class
|
127
125
|
resource_class.first(id: qr.id, uuid: qr.uuid, name: qr.name) # TODO: Does this create a DB call?
|
@@ -188,7 +186,10 @@ module OMF::SFA::Resource
|
|
188
186
|
elsif val.is_a? OResource
|
189
187
|
return {v: val.uuid.to_s, t: 'r', f: :s_value}
|
190
188
|
elsif val.is_a? Time
|
191
|
-
return {v: val.to_i, t: '
|
189
|
+
return {v: val.to_i, t: 't', f: :n_value}
|
190
|
+
elsif val.class.included_modules.include?(DataMapper::Resource)
|
191
|
+
#puts "SET>>>>> #{val}:#{val.class}"
|
192
|
+
return {v: "#{val.class}@#{val.id}", t: 'd', f: :s_value}
|
192
193
|
else
|
193
194
|
#debug "SETTING VALUE> Class: #{val.class}"
|
194
195
|
return {v: JSON.generate([val]), t: 'o', f: :s_value}
|
@@ -208,6 +209,12 @@ module OMF::SFA::Resource
|
|
208
209
|
val = OResource.first(uuid: uuid)
|
209
210
|
when 't'
|
210
211
|
val = Time.at(attribute_get(:n_value))
|
212
|
+
when 'd'
|
213
|
+
v = attribute_get(:s_value)
|
214
|
+
klass_s, id_s = v.split('@')
|
215
|
+
klass = klass_s.split('::').inject(Kernel) {|k, s| k.const_get(s) }
|
216
|
+
val = klass.first(id: id_s.to_i)
|
217
|
+
#puts "GET>>>>> #{v} - #{val}"
|
211
218
|
when 'o'
|
212
219
|
js = attribute_get(:s_value)
|
213
220
|
#debug "GET VALUE> <#{js}>"
|
@@ -253,7 +260,7 @@ module OMF::SFA::Resource
|
|
253
260
|
end
|
254
261
|
|
255
262
|
def to_s()
|
256
|
-
|
263
|
+
"#<#{self.class} id: #{self.id} subj: #{self.o_resource} name: #{self.name} value: #{self.value}>"
|
257
264
|
end
|
258
265
|
|
259
266
|
#before :save do
|
@@ -273,9 +280,12 @@ module OMF::SFA::Resource
|
|
273
280
|
|
274
281
|
class OPropertyArray
|
275
282
|
def <<(val)
|
283
|
+
#puts ">>> Adding #{val} to #{@name} - #{@on_set_block}"
|
276
284
|
p = OProperty.create(name: @name, o_resource: @resource)
|
285
|
+
if @on_set_block
|
286
|
+
val = @on_set_block.call(val)
|
287
|
+
end
|
277
288
|
p.value = val
|
278
|
-
@on_set_block.call(val) if @on_set_block
|
279
289
|
self
|
280
290
|
end
|
281
291
|
|
@@ -287,15 +297,9 @@ module OMF::SFA::Resource
|
|
287
297
|
|
288
298
|
[:each, :each_with_index, :select, :map].each do |n|
|
289
299
|
define_method n do |&block|
|
290
|
-
c = OProperty.all(name: @name, o_resource: @resource)
|
291
|
-
|
292
|
-
|
293
|
-
val = prop.value
|
294
|
-
val = @on_set_block.call(val) if @on_set_block
|
295
|
-
y << val
|
296
|
-
end
|
297
|
-
end
|
298
|
-
e.send(n, &block)
|
300
|
+
#c = OProperty.all(name: @name, o_resource: @resource)
|
301
|
+
c = self.to_a()
|
302
|
+
c.send(n, &block)
|
299
303
|
end
|
300
304
|
end
|
301
305
|
|
@@ -313,6 +317,10 @@ module OMF::SFA::Resource
|
|
313
317
|
@on_set_block = block
|
314
318
|
end
|
315
319
|
|
320
|
+
def to_a
|
321
|
+
OProperty.all(name: @name, o_resource: @resource).all.map {|p| p.value }
|
322
|
+
end
|
323
|
+
|
316
324
|
def to_json(*args)
|
317
325
|
OProperty.all(name: @name, o_resource: @resource).map do |p|
|
318
326
|
p.value
|
@@ -83,7 +83,7 @@ module OMF::SFA::Resource
|
|
83
83
|
op[pname] = opts
|
84
84
|
|
85
85
|
define_method pname do
|
86
|
-
res = oproperty_array_get(pname)
|
86
|
+
res = oproperty_array_get(pname, opts[:set_filter])
|
87
87
|
if res == nil
|
88
88
|
oproperty_set(pname, [])
|
89
89
|
# We make a oproperty_get in order to get the extended Array with
|
@@ -106,11 +106,6 @@ module OMF::SFA::Resource
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
|
-
if sf = opts[:set_filter]
|
110
|
-
res.on_set do |v|
|
111
|
-
self.send(sf, v)
|
112
|
-
end
|
113
|
-
end
|
114
109
|
res
|
115
110
|
end
|
116
111
|
|
@@ -118,7 +113,7 @@ module OMF::SFA::Resource
|
|
118
113
|
# helps other entities to learn if this property is functional or not.
|
119
114
|
#
|
120
115
|
define_method "#{pname}_add" do |v|
|
121
|
-
oproperty_array_get(pname) << v
|
116
|
+
oproperty_array_get(pname, opts[:set_filter]) << v
|
122
117
|
#self.send(pname.to_sym) << v
|
123
118
|
end
|
124
119
|
|
@@ -127,8 +122,9 @@ module OMF::SFA::Resource
|
|
127
122
|
raise "Property '#{pname}' in '#{self.class}' requires an Array in setter - #{v.inspect}"
|
128
123
|
end
|
129
124
|
#res = self.send(pname.to_sym)
|
130
|
-
res = oproperty_array_get(pname)
|
125
|
+
res = oproperty_array_get(pname, opts[:set_filter])
|
131
126
|
res.clear # clear any old values
|
127
|
+
#puts ">>>> SET: #{v} - #{res}"
|
132
128
|
v.each {|it| res << it }
|
133
129
|
res
|
134
130
|
end
|
@@ -265,9 +261,19 @@ module OMF::SFA::Resource
|
|
265
261
|
end
|
266
262
|
alias_method :[]=, :oproperty_set
|
267
263
|
|
268
|
-
def oproperty_array_get(pname)
|
264
|
+
def oproperty_array_get(pname, set_filter)
|
269
265
|
pname = pname.to_sym
|
270
|
-
ap = (@array_properties ||= {})[pname]
|
266
|
+
unless ap = (@array_properties ||= {})[pname]
|
267
|
+
ap = OPropertyArray.new(self, pname)
|
268
|
+
if set_filter
|
269
|
+
# TODO: The following block can most likely be optimised away
|
270
|
+
ap.on_set do |v|
|
271
|
+
self.send(set_filter, v)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
@array_properties[pname] = ap
|
275
|
+
end
|
276
|
+
ap
|
271
277
|
end
|
272
278
|
|
273
279
|
def oproperties_as_hash
|
data/lib/omf-sfa/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omf_sfa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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-02-
|
12
|
+
date: 2014-02-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|