Class: Leadlight::TypeMap
- Inherits:
-
Object
- Object
- Leadlight::TypeMap
- Defined in:
- lib/leadlight/type_map.rb
Defined Under Namespace
Classes: DefaultType, Mapping
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #add(enctype_pattern, object_pattern, type) ⇒ Object
-
#initialize(options = {}) ⇒ TypeMap
constructor
A new instance of TypeMap.
- #to_entity_body(object, options = {}) ⇒ Object
- #to_native(content_type, entity_body, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TypeMap
Returns a new instance of TypeMap.
13 14 15 16 17 18 19 |
# File 'lib/leadlight/type_map.rb', line 13 def initialize(={}) .each do |key, value| send key, value end @types = [] add_default_types end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
11 12 13 |
# File 'lib/leadlight/type_map.rb', line 11 def types @types end |
Instance Method Details
#add(enctype_pattern, object_pattern, type) ⇒ Object
21 22 23 |
# File 'lib/leadlight/type_map.rb', line 21 def add(enctype_pattern, object_pattern, type) types.unshift(Mapping.new(enctype_pattern, object_pattern, type)) end |
#to_entity_body(object, options = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/leadlight/type_map.rb', line 25 def to_entity_body(object, ={}) types.detect(handle_unknown_object_type(object)) {|t| t.match_for_object?(object) }.encode(object, ) end |
#to_native(content_type, entity_body, options = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/leadlight/type_map.rb', line 31 def to_native(content_type, entity_body, ={}) types.detect(handle_unknown_enctype(content_type)) {|t| t.match_for_enctype?(content_type) }.decode(content_type, entity_body, ) end |