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.



338
339
340
341
# File 'lib/omf-sfa/resource/oproperty.rb', line 338

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

Instance Method Details

#<<(val) ⇒ Object



285
286
287
288
289
290
291
292
293
294
# File 'lib/omf-sfa/resource/oproperty.rb', line 285

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

#clearObject

Delete all members



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

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

#empty?Boolean

Returns:

  • (Boolean)


310
311
312
# File 'lib/omf-sfa/resource/oproperty.rb', line 310

def empty?
  OProperty.count(name: @name, o_resource: @resource) == 0
end

#on_modified(&block) ⇒ Object

Callback to support ‘reverse’ operation



315
316
317
318
# File 'lib/omf-sfa/resource/oproperty.rb', line 315

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

#on_set(&block) ⇒ Object



320
321
322
# File 'lib/omf-sfa/resource/oproperty.rb', line 320

def on_set(&block)
  @on_set_block = block
end

#to_aObject



324
325
326
# File 'lib/omf-sfa/resource/oproperty.rb', line 324

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

#to_json(*args) ⇒ Object



328
329
330
331
332
# File 'lib/omf-sfa/resource/oproperty.rb', line 328

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

#to_sObject



334
335
336
# File 'lib/omf-sfa/resource/oproperty.rb', line 334

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