Class: OMF::SFA::Resource::OPropertyArray

Inherits:
Object
  • Object
show all
Defined in:
lib/omf-sfa/resource/oproperty.rb

Overview

OProperty

Instance Method Summary collapse

Constructor Details

#initialize(resource, name) ⇒ OPropertyArray

Returns a new instance of OPropertyArray.



302
303
304
305
# File 'lib/omf-sfa/resource/oproperty.rb', line 302

def initialize(resource, name)
  @resource = resource
  @name = name
end

Instance Method Details

#<<(val) ⇒ Object



237
238
239
240
241
242
243
244
245
246
# File 'lib/omf-sfa/resource/oproperty.rb', line 237

def <<(val)
  #puts ">>> Adding #{val} to #{@name} - #{@on_set_block}"
  p = OProperty.create(name: @name, o_resource: @resource)
  if @on_set_block
    val = @on_set_block.call(val)
    return if val.nil? #
  end
  p.value = val
  self
end

#[](index) ⇒ Object



262
263
264
265
266
267
268
# File 'lib/omf-sfa/resource/oproperty.rb', line 262

def [](index)
  if p = OProperty.all(name: @name, o_resource: @resource).all[index]
    p.value
  else
    nil
  end
end

#clearObject

Delete all members



249
250
251
252
# File 'lib/omf-sfa/resource/oproperty.rb', line 249

def clear
  OProperty.all(name: @name, o_resource: @resource).destroy
  self
end

#empty?Boolean

Returns:

  • (Boolean)


274
275
276
# File 'lib/omf-sfa/resource/oproperty.rb', line 274

def empty?
  self.length == 0
end

#lengthObject



270
271
272
# File 'lib/omf-sfa/resource/oproperty.rb', line 270

def length
  OProperty.count(name: @name, o_resource: @resource)
end

#on_modified(&block) ⇒ Object

Callback to support ‘reverse’ operation



279
280
281
282
# File 'lib/omf-sfa/resource/oproperty.rb', line 279

def on_modified(&block)
  raise "Not implemented"
  #@on_modified_block = block
end

#on_set(&block) ⇒ Object



284
285
286
# File 'lib/omf-sfa/resource/oproperty.rb', line 284

def on_set(&block)
  @on_set_block = block
end

#to_aObject



288
289
290
# File 'lib/omf-sfa/resource/oproperty.rb', line 288

def to_a
  OProperty.all(name: @name, o_resource: @resource).all.map {|p| p.value }
end

#to_json(*args) ⇒ Object



292
293
294
295
296
# File 'lib/omf-sfa/resource/oproperty.rb', line 292

def to_json(*args)
  OProperty.all(name: @name, o_resource: @resource).map do |p|
    p.value
  end.to_json(*args)
end

#to_sObject



298
299
300
# File 'lib/omf-sfa/resource/oproperty.rb', line 298

def to_s
  "<#{self.class}: name=#{@name} resource=#{@resource.name || @resource.uuid} >"
end