Class: Reins::Controller::FormatCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/reins/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFormatCollector

Returns a new instance of FormatCollector.



277
278
279
280
# File 'lib/reins/controller.rb', line 277

def initialize
  @ordered_formats = []
  @handlers = {}
end

Instance Attribute Details

#handlersObject (readonly)

Returns the value of attribute handlers.



275
276
277
# File 'lib/reins/controller.rb', line 275

def handlers
  @handlers
end

#ordered_formatsObject (readonly)

Returns the value of attribute ordered_formats.



275
276
277
# File 'lib/reins/controller.rb', line 275

def ordered_formats
  @ordered_formats
end

Instance Method Details

#html(&block) ⇒ Object



282
# File 'lib/reins/controller.rb', line 282

def html(&block) = register(:html, "text/html", block)

#json(&block) ⇒ Object



283
# File 'lib/reins/controller.rb', line 283

def json(&block) = register(:json, "application/json", block)

#register(name, mime, block) ⇒ Object



285
286
287
288
# File 'lib/reins/controller.rb', line 285

def register(name, mime, block)
  @ordered_formats << name
  @handlers[name] = { mime: mime, block: block }
end