Class: ActiveEntity::ConversionDefinitions::MapWithNormalizing
- Inherits:
-
Object
- Object
- ActiveEntity::ConversionDefinitions::MapWithNormalizing
- Defined in:
- lib/active_entity/conversion_definitions.rb
Instance Method Summary collapse
- #get(type) ⇒ Object
-
#initialize ⇒ MapWithNormalizing
constructor
A new instance of MapWithNormalizing.
- #normalize_type(type) ⇒ Object
- #set(type, &block) ⇒ Object
Constructor Details
#initialize ⇒ MapWithNormalizing
Returns a new instance of MapWithNormalizing.
35 36 37 |
# File 'lib/active_entity/conversion_definitions.rb', line 35 def initialize @map = {} end |
Instance Method Details
#get(type) ⇒ Object
39 40 41 |
# File 'lib/active_entity/conversion_definitions.rb', line 39 def get(type) @map[normalize_type(type)] end |
#normalize_type(type) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/active_entity/conversion_definitions.rb', line 48 def normalize_type(type) case type when Class type.to_s when String type when Symbol type.to_s else raise ArgumentError.new("`type` must be a Class or String or Symbol, but #{type.class}") end end |
#set(type, &block) ⇒ Object
43 44 45 46 |
# File 'lib/active_entity/conversion_definitions.rb', line 43 def set(type, &block) # TODO: block arity check @map[normalize_type(type)] = block end |