Develop a model layer for a file system persisted in a SQL database where it's possible to create directories and files. The directories can contain subdirectories and files. The file contents can be persisted as blob, S3, or on disk.
The solution should be written primarily in Ruby using the Ruby on Rails framework.
- Docker and Docker Compose
- Ruby 3.4.3
Optional
- jq (
sudo apt-get install jqorbrew install jq) - curl
- Clone the repository:
git clone <repository-url>
cd ruby-dev-test-1- Build the Docker image:
docker compose build- Setup the database:
docker compose run app bin/rails db:setupStart the application:
docker compose upRunning migrations
docker compose run app bin/rails db:migrateThe API will be available at http://localhost:1234
Returns all root-level directories.
curl -X GET http://localhost:1234/directories | jqReturns a specific directory and its complete subtree.
curl -X GET http://localhost:1234/directories/:id | jqCreates a new directory. Set parent_id to create a subdirectory.
# Create root directory
curl -X POST http://localhost:1234/directories \
-H "Content-Type: application/json" \
-d '{
"directory": {
"name": "New Root Directory",
"parent_id": null
}
}' | jq
# Create subdirectory
curl -X POST http://localhost:1234/directories \
-H "Content-Type: application/json" \
-d '{
"directory": {
"name": "Subdirectory",
"parent_id": 1
}
}' | jqDelete a specific directory.
curl -X DELETE http://localhost:1234/directories/:id | jqUpload one or multiple files to a directory.
# Upload single file
(echo "File 1 content" > /tmp/file1.txt && \
curl -X POST http://localhost:1234/directories/:directory_id/files \
-F "files[]=@/tmp/file1.txt" | jq && \
rm /tmp/file1.txt)
# Upload multiple files
(echo "File 1 content" > /tmp/file1.txt && \
echo "File 2 content" > /tmp/file2.txt && \
curl -X POST http://localhost:1234/directories/:directory_id/files \
-F "files[]=@/tmp/file1.txt" \
-F "files[]=@/tmp/file2.txt" | jq && \
rm /tmp/file1.txt /tmp/file2.txt)Delete a specific file from a directory.
curl -X DELETE http://localhost:1234/directories/:directory_id/files/:id | jq- Install development dependencies:
docker compose run app bundle install- Run the test suite:
docker compose run -e RAILS_ENV=test app bash -c "bin/rails db:migrate && bundle exec rspec"- Remove all containers and volumes:
docker compose down -v