Module: AcDc::Mapping::ClassMethods
- Defined in:
- lib/acdc/mapping.rb
Instance Method Summary collapse
- #attribute(name, type, options = {}) ⇒ Object
- #attributes ⇒ Object
- #element(name, type, options = {}) ⇒ Object
- #elements ⇒ Object
- #make_accessor(item) ⇒ Object
- #namespace(namespace = nil) ⇒ Object
- #tag_name(name = nil) ⇒ Object
Instance Method Details
#attribute(name, type, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/acdc/mapping.rb', line 20 def attribute(name, type, ={}) attribute = Attribute.new(name,type,) @attributes[to_s] ||= [] @attributes[to_s] << attribute unless @inheritance_chain.nil? @inheritance_chain.each { |child| child.attribute(name,type,) } end make_accessor(attribute) end |
#attributes ⇒ Object
12 13 14 |
# File 'lib/acdc/mapping.rb', line 12 def attributes @attributes[to_s] || [] end |
#element(name, type, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/acdc/mapping.rb', line 30 def element(name, type, ={}) element = Element.new(name,type,) @elements[to_s] ||= [] @elements[to_s] << element unless @inheritance_chain.nil? @inheritance_chain.each { |child| child.element(name,type,) } end make_accessor(element) end |
#elements ⇒ Object
16 17 18 |
# File 'lib/acdc/mapping.rb', line 16 def elements @elements[to_s] || [] end |
#make_accessor(item) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/acdc/mapping.rb', line 50 def make_accessor(item) in_elems = elements.find{|e| e.name == item.name and e != item} in_attrs = attributes.find{|a| a.name == item.name and a != item} if in_elems or in_attrs name = "#{item.element? ? "element_" : "attribute_"}#{item.name}" item.name = name end attr_accessor item.method_name.intern end |
#namespace(namespace = nil) ⇒ Object
45 46 47 48 |
# File 'lib/acdc/mapping.rb', line 45 def namespace(namespace = nil) @namespace = namespace if namespace @namespace end |
#tag_name(name = nil) ⇒ Object
40 41 42 43 |
# File 'lib/acdc/mapping.rb', line 40 def tag_name(name = nil) @tag_name = name.to_s if name @tag_name ||= to_s.split('::')[-1].downcase end |