Class: Muxml::Base::Relation::One

Inherits:
Object
  • Object
show all
Defined in:
lib/muxml/relation.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj, relation, options = {}) ⇒ One

Returns a new instance of One.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/muxml/relation.rb', line 6

def initialize(obj, relation, options = {})
  @obj = obj
  @relation = relation
  @tag = options.delete(:tag)
  @class_name = options.delete(:class_name)
  @query = options.delete(:select)
  @options = options

  raise ArgumentError, "#{obj.class.to_s} :class_name is nil" if @class_name.nil?
  raise ArgumentError, "#{obj.class.to_s} :tag is nil" if @tag.nil?
  unless @query.nil?
    attributes = @query.map{|k,v| "@#{k}='#{v}'"}.join
    @find_query = "#{@tag}[#{attributes}]"
  else
    @find_query = "#{@tag}"
  end

  @element =  Object.const_get(@class_name).new(obj.xml.elements[@find_query])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



26
27
28
# File 'lib/muxml/relation.rb', line 26

def method_missing(sym, *args, &block)
  @element.send(sym, *args, &block)
end