Class: OMF::SFA::Resource::OPropertyArray
- Inherits:
-
Object
- Object
- OMF::SFA::Resource::OPropertyArray
- Defined in:
- lib/omf-sfa/resource/oproperty.rb
Overview
OProperty
Instance Method Summary collapse
- #<<(val) ⇒ Object
-
#clear ⇒ Object
Delete all members.
- #empty? ⇒ Boolean
-
#initialize(resource, name) ⇒ OPropertyArray
constructor
A new instance of OPropertyArray.
-
#on_modified(&block) ⇒ Object
Callback to support ‘reverse’ operation.
- #on_set(&block) ⇒ Object
- #to_a ⇒ Object
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object
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 |
#clear ⇒ Object
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
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_a ⇒ Object
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_s ⇒ Object
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 |