Class: SerializationSelectorDsl

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/media_types/serialization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, selected_serializer) ⇒ SerializationSelectorDsl

Returns a new instance of SerializationSelectorDsl.



26
27
28
29
30
31
# File 'lib/media_types/serialization.rb', line 26

def initialize(controller, selected_serializer)
  @serializer = selected_serializer
  self.value = nil
  self.matched = false
  super controller
end

Instance Attribute Details

#matchedObject

Returns the value of attribute matched.



33
34
35
# File 'lib/media_types/serialization.rb', line 33

def matched
  @matched
end

#valueObject

Returns the value of attribute value.



33
34
35
# File 'lib/media_types/serialization.rb', line 33

def value
  @value
end

Instance Method Details

#serializer(klazz, obj = nil, &block) ⇒ Object



35
36
37
38
39
40
# File 'lib/media_types/serialization.rb', line 35

def serializer(klazz, obj = nil, &block)
  return if klazz != @serializer

  self.matched = true
  self.value = block.nil? ? obj : yield
end