Class: Peanuts::Mappings::MemberMapping
- Inherits:
-
Peanuts::Mapping
- Object
- Peanuts::Mapping
- Peanuts::Mappings::MemberMapping
- Defined in:
- lib/peanuts/mappings.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#converter ⇒ Object
readonly
Returns the value of attribute converter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from Peanuts::Mapping
#options, #prefix, #xmlname, #xmlns
Instance Method Summary collapse
- #clear(nut) ⇒ Object
-
#initialize(name, type, options) ⇒ MemberMapping
constructor
A new instance of MemberMapping.
- #restore(nut, reader) ⇒ Object
- #save(nut, writer) ⇒ Object
Methods inherited from Peanuts::Mapping
Constructor Details
#initialize(name, type, options) ⇒ MemberMapping
Returns a new instance of MemberMapping.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/peanuts/mappings.rb', line 36 def initialize(name, type, ) super(.delete(:xmlname) || name, ) case type when Array raise ArgumentError, "invalid value for type: #{type.inspect}" if type.length != 1 [:item_type] = type.first @converter = Converter.create!(:list, ) when Class [:object_type] = type else @converter = Converter.create!(type, ) end @name, @setter, @type = name.to_sym, :"#{name}=", type end |
Instance Attribute Details
#converter ⇒ Object (readonly)
Returns the value of attribute converter.
34 35 36 |
# File 'lib/peanuts/mappings.rb', line 34 def converter @converter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/peanuts/mappings.rb', line 34 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
34 35 36 |
# File 'lib/peanuts/mappings.rb', line 34 def type @type end |
Instance Method Details
#clear(nut) ⇒ Object
59 60 61 |
# File 'lib/peanuts/mappings.rb', line 59 def clear(nut) set(nut, nil) end |
#restore(nut, reader) ⇒ Object
55 56 57 |
# File 'lib/peanuts/mappings.rb', line 55 def restore(nut, reader) set(nut, restore_value(reader, get(nut))) end |
#save(nut, writer) ⇒ Object
51 52 53 |
# File 'lib/peanuts/mappings.rb', line 51 def save(nut, writer) save_value(writer, get(nut)) end |