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.17.14 lib/brief/server/handlers/action.rb
brief-1.17.13 lib/brief/server/handlers/action.rb
brief-1.17.12 lib/brief/server/handlers/action.rb
brief-1.17.11 lib/brief/server/handlers/action.rb
brief-1.17.10 lib/brief/server/handlers/action.rb
brief-1.17.9 lib/brief/server/handlers/action.rb
brief-1.17.8 lib/brief/server/handlers/action.rb
brief-1.17.7 lib/brief/server/handlers/action.rb
brief-1.17.5 lib/brief/server/handlers/action.rb
brief-1.17.4 lib/brief/server/handlers/action.rb
brief-1.17.3 lib/brief/server/handlers/action.rb
brief-1.17.2 lib/brief/server/handlers/action.rb
brief-1.17.1 lib/brief/server/handlers/action.rb
brief-1.17.0 lib/brief/server/handlers/action.rb
brief-1.16.2 lib/brief/server/handlers/action.rb
brief-1.16.1 lib/brief/server/handlers/action.rb
brief-1.16.0 lib/brief/server/handlers/action.rb
brief-1.15.5 lib/brief/server/handlers/action.rb
brief-1.15.4 lib/brief/server/handlers/action.rb
brief-1.15.3 lib/brief/server/handlers/action.rb