Logo: Relish

  1. Sign in

Project: Piano-spec

Controllers

Controller files

The piano command searches for a controllers folder in the
working directory.

If it finds the folder, searches recursively in it for files
finished in .controller. Finally, it loads them all, after the Pianofile
but before the default routes.

Configuration

The controllers folder is configurable both in the Pianofile or via
command line arguments.

Via argument

> piano controllers:app/controllers

In the Pianofile

set :controllers, "app/controllers"

Loading order

piano loads the controllers in the order it finds them. The algorithm
is not yet determined.

Try not to set the same route twice in different .controller files
because it might lead to erratic behavior.

Scenarios
  • @piano
  • @controllers
There is a controller in the folder
Given
the "arena" folder has a "controllers/demo.controller" with:
get "/" do
  "demo.controller loaded"
end
When
the piano command is called
And
I go to "http://localhost:4567/"
Then
I should see "demo.controller loaded"
  • @piano
  • @controllers
There is a file not ended in .controller in the folder
Given
the "arena" folder has a "controllers/demo.rb" with:
get "/" do
  "demo.rb loaded"
end
When
the piano command is called
And
I go to "http://localhost:4567/"
Then
I should not see "demo.rb loaded"
  • @piano
  • @controllers
There is a controller inside a subdirectory
Given
the "arena" folder has a "controllers/inside/this.controller" with:
get "/" do
  "inside/this.controller loaded"
end
When
the piano command is called
And
I go to "http://localhost:4567/"
Then
I should see "inside/this.controller loaded"
  • @piano
  • @controllers
  • @wip
There is more than one controller and a non controller
Given
the "arena" folder has a "controllers/inside/my.controller" with:
get "/my" do
  "inside/my.controller loaded"
end
And
the "arena" folder has a "controllers/index.controller" with:
get "/" do
  "index.controller loaded"
end
And
the "arena" folder has a "controllers/index.rb" with:
get "/rb" do
  "index.rb loaded"
end
When
the piano command is called
And
I go to "http://localhost:4567/my"
Then
I should see "inside/my.controller loaded"
When
I go to "http://localhost:4567/"
Then
I should see "index.controller loaded"
When
I go to "http://localhost:4567/rb"
Then
I should not see "index.rb loaded"
  • @piano
  • @controllers
  • @wip
Change the controllers folder via command line argument
Given
the "arena" folder has a "apps/controllers/index.controller" with:
get "/" do
  "index.controller loaded"
end
When
the piano controllers:apps/controllers command is called
And
I go to "http://localhost:4567/"
Then
I should see "index.controller loaded"

Last published over 7 years ago by xaviervia.