Sha256: a31bf6d45a0441333d2775910b75e565e3e0b3d800587e1650f8cb35c577ee85

Contents?: true

Size: 679 Bytes

Versions: 89

Compression:

Stored size: 679 Bytes

Contents

module Brief::Server::Handlers
  class Action
    def self.handle(path_args, briefcase, options={})
      parts = path_args.split("/")
      action = parts.shift
      path = parts.join("/")

      document = briefcase.document_at(path)

      headers = {
        "Content-Type" => "application/json"
      }

      if !document
        return [404,headers,{error:"Could not find a document at this path"}]
      end

      model = document.to_model

      if !model.class.defined_actions.include?(action.to_sym)
        [400, headers, {error:"Invalid action: #{ action }"}]
      else
        model.send(action)
        [200, headers, model.as_json]
      end
    end
  end
end

Version data entries

89 entries across 89 versions & 1 rubygems

Version Path
brief-1.11.9 lib/brief/server/handlers/action.rb
brief-1.11.8 lib/brief/server/handlers/action.rb
brief-1.11.7 lib/brief/server/handlers/action.rb
brief-1.11.6 lib/brief/server/handlers/action.rb
brief-1.11.5 lib/brief/server/handlers/action.rb
brief-1.11.4 lib/brief/server/handlers/action.rb
brief-1.11.3 lib/brief/server/handlers/action.rb
brief-1.11.2 lib/brief/server/handlers/action.rb
brief-1.11.1 lib/brief/server/handlers/action.rb
brief-1.11.0 lib/brief/server/handlers/action.rb
brief-1.10.1 lib/brief/server/handlers/action.rb
brief-1.10.0 lib/brief/server/handlers/action.rb
brief-1.9.14 lib/brief/server/handlers/action.rb
brief-1.9.13 lib/brief/server/handlers/action.rb
brief-1.9.12 lib/brief/server/handlers/action.rb
brief-1.9.11 lib/brief/server/handlers/action.rb
brief-1.9.9 lib/brief/server/handlers/action.rb
brief-1.9.8 lib/brief/server/handlers/action.rb
brief-1.9.7 lib/brief/server/handlers/action.rb
brief-1.9.6 lib/brief/server/handlers/action.rb