Class: RTunesU::HasAEntityCollectionProxy

Inherits:
SubentityAssociationProxy show all
Defined in:
lib/rtunesu/associations.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SubentityAssociationProxy

#initialize

Constructor Details

This class inherits a constructor from RTunesU::SubentityAssociationProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



42
43
44
# File 'lib/rtunesu/associations.rb', line 42

def method_missing(method_name, *args)
  @target.send(method_name, args)
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



15
16
17
# File 'lib/rtunesu/associations.rb', line 15

def target
  @target
end

Class Method Details

.new_from_target(target, owner, name) ⇒ Object



24
25
26
27
28
# File 'lib/rtunesu/associations.rb', line 24

def self.new_from_target(target, owner, name)
  proxy = self.new(nil, owner, name)
  proxy.instance_variable_set("@target", target)
  return proxy
end

.new_or_nil(source_xml, owner, name) ⇒ Object



17
18
19
20
21
22
# File 'lib/rtunesu/associations.rb', line 17

def self.new_or_nil(source_xml, owner, name)
  return nil if source_xml.empty?
  proxy = self.new(source_xml, owner, name)
  proxy.from_xml(name)
  return proxy
end

Instance Method Details

#from_xml(name) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/rtunesu/associations.rb', line 30

def from_xml(name)
  if @source_xml
   @target = "RTunesU::#{name}".constantize.new(:source_xml => @source_xml.first, :parent_handle => @owner.handle)
  else
   @target = "RTunesU::#{name}".constantize.new(:parent_handle => @owner.handle)
  end
end

#to_xml(xml_builder = Builder::XmlMarkup.new) ⇒ Object



38
39
40
# File 'lib/rtunesu/associations.rb', line 38

def to_xml(xml_builder = Builder::XmlMarkup.new)
  @target.to_xml(xml_builder) if @target.edits.any?
end