Module: Roar::Rails::ControllerAdditions

Extended by:
ActiveSupport::Concern
Defined in:
lib/roar/rails/controller_additions.rb

Defined Under Namespace

Modules: ClassMethods Classes: RepresenterComputer

Instance Method Summary collapse

Instance Method Details

#consume!(model, options = {}) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/roar/rails/controller_additions.rb', line 27

def consume!(model, options={})
  format      = formats.first  # FIXME: i expected request.content_mime_type to do the job. copied from responder.rb. this will return the wrong format when the controller responds to :json and :xml and the Content-type is :xml (?)
  representer = prepare_model_for(format, model, options)

  representer.send(compute_parsing_method(format), incoming_string, options) # e.g. from_json("...")
  model
end

#prepare_model_for(format, model, options) ⇒ Object



35
36
37
38
# File 'lib/roar/rails/controller_additions.rb', line 35

def prepare_model_for(format, model, options)
  representer = representer_for(format, model, options)
  representer.prepare(model)
end

#representer_for(format, model, options = {}) ⇒ Object

Central entry-point for finding the appropriate representer.



41
42
43
# File 'lib/roar/rails/controller_additions.rb', line 41

def representer_for(format, model, options={})
  options.delete(:represent_with) || self.class.represents_options.for(format, model, controller_path)
end