Class: Brief::Server::Handlers::Browse

Inherits:
Object
  • Object
show all
Defined in:
lib/brief/server/handlers/browse.rb

Class Method Summary collapse

Class Method Details

.available_handlersObject



3
4
5
# File 'lib/brief/server/handlers/browse.rb', line 3

def self.available_handlers
  Brief::Model.classes.map(&:type_alias).map(&:pluralize)
end

.handle(path_args, briefcase, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/brief/server/handlers/browse.rb', line 7

def self.handle(path_args, briefcase, options={})
  model_type = Array(path_args).first

  if available_handlers.include?(model_type)
    models = briefcase.send(model_type.to_s)

    presented_models = models.map do |model|
      model.as_json(options.symbolize_keys)
    end

    [200, {"Content-Type"=>"application/json"}, presented_models]
  else
    [403, {"Content-Type"=>"application/json"}, {error: "Invalid model type"}]
  end
end