Class: Muxml::Base::Relation::One
- Inherits:
-
Object
- Object
- Muxml::Base::Relation::One
- Defined in:
- lib/muxml/relation.rb
Instance Method Summary collapse
-
#initialize(obj, relation, options = {}) ⇒ One
constructor
A new instance of One.
- #method_missing(sym, *args, &block) ⇒ Object
Constructor Details
#initialize(obj, relation, options = {}) ⇒ One
Returns a new instance of One.
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, = {}) @obj = obj @relation = relation @tag = .delete(:tag) @class_name = .delete(:class_name) @query = .delete(:select) @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 |