Module: WCC::Arena::Mappers::XML::ClassMethods
- Defined in:
- lib/wcc/arena/mappers/xml.rb
Instance Method Summary collapse
- #add_association(name, options, &block) ⇒ Object
- #associations ⇒ Object
- #attribute(name, options) ⇒ Object
- #attributes ⇒ Object
- #has_many(name, options) ⇒ Object
- #has_one(name, options) ⇒ Object
- #inherited(subclass) ⇒ Object
Instance Method Details
#add_association(name, options, &block) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/wcc/arena/mappers/xml.rb', line 103 def add_association(name, , &block) .fetch(:xpath) { raise ArgumentError, ":xpath is a required argument" } .fetch(:klass) { raise ArgumentError, ":klass is a required argument" } .fetch(:type) { raise ArgumentError, ":type is a required argument" } associations[name] = .freeze define_method(name, &block) if block_given? end |
#associations ⇒ Object
85 86 87 |
# File 'lib/wcc/arena/mappers/xml.rb', line 85 def associations @associations ||= {} end |
#attribute(name, options) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/wcc/arena/mappers/xml.rb', line 73 def attribute(name, ) .fetch(:xpath) { raise ArgumentError, ":xpath is a required argument to the `attribute' method" } attributes[name] = .freeze define_method(name) { self[name] } end |
#attributes ⇒ Object
81 82 83 |
# File 'lib/wcc/arena/mappers/xml.rb', line 81 def attributes @attributes ||= {} end |
#has_many(name, options) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/wcc/arena/mappers/xml.rb', line 96 def has_many(name, ) add_association(name, .merge(type: :many)) do @association_cache ||= {} @association_cache[name] ||= load_association(name) end end |
#has_one(name, options) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/wcc/arena/mappers/xml.rb', line 89 def has_one(name, ) add_association(name, .merge(type: :one)) do @association_cache ||= {} @association_cache[name] ||= load_association(name) end end |
#inherited(subclass) ⇒ Object
117 118 119 120 121 |
# File 'lib/wcc/arena/mappers/xml.rb', line 117 def inherited(subclass) super subclass.instance_variable_set(:@attributes, attributes.dup) subclass.instance_variable_set(:@associations, associations.dup) end |