roda-project 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: beb637fce10cb01a9d71fbcceca4b10ccc6e04aa05bac094fc6327ed1854643e
4
- data.tar.gz: 1ac1a13838ba8a5f5e6c65409e192ab9b15fe3f5ad9ee14dbc9d5b648a195434
3
+ metadata.gz: 6fa6f449cc4a6f6e7342135d2de859c481b517dc9666ca9e9d64bbc5141b27b5
4
+ data.tar.gz: f95248f05abe4a1df4b5cd1018823c9243d1fa27fab9904b6f3c9dc966f972e4
5
5
  SHA512:
6
- metadata.gz: 471336f81ca6fd96226a001e599debeeb22302a284a78e8911a5bf0be02dd78c8010272b061f868d185ed82f3c943f84f6f90e2b35f44c807b2778027a24c019
7
- data.tar.gz: 4ced8204c150d5208961c2315256151cd0eca3f2bd48905979684490450decc760f8d1b3828ac075fa1539d8e542ff4821cebfe0f70aa4df281efc0cc874e63a
6
+ metadata.gz: 9022aca6837ac8803328e3d785514fe3c93d9bdbd2a272c1eee5c1ea231298543db5ef3840fd53f83ba5a6f56d92199a1750d8462635b3146ddb6adea4407067
7
+ data.tar.gz: a589f4edadacd2f4aa54a5ef53526764c6bebefbacc16553768fc0d24a38851c7744577c843279d84a8976a287aeb0208f37e66f15e6f2ec5a8e4c0a4a060645
@@ -24,10 +24,10 @@ class Roda
24
24
  route_definitions = routes_list.map do |route_str|
25
25
  method, name = parse_route_string(route_str)
26
26
  view_name = name
27
- view_name = "index" if view_name == ""
27
+ view_name = "index" if view_name == nil
28
28
  view_line = (method == "get" && must_generate_views?) ? "\n view('#{view_name}')" : ""
29
29
 
30
- if name != ""
30
+ if name != nil
31
31
  " r.#{method} \"#{name}\" do#{view_line}\n end"
32
32
  else
33
33
  " r.#{method} do#{view_line}\n end"
@@ -61,7 +61,7 @@ class Roda
61
61
  routes_list.each do |route_str|
62
62
  method, name = parse_route_string(route_str)
63
63
  if method == "get"
64
- name = "index" if name == ""
64
+ name = "index" if name == nil
65
65
  view_filename = File.join(branch_views_dir, "#{name}.erb")
66
66
  File.write(view_filename, "")
67
67
  action_success_message(view_filename)
@@ -78,7 +78,7 @@ class Roda
78
78
  test_route_definitions = routes_list.map do |route_str|
79
79
  method, name = parse_route_string(route_str)
80
80
 
81
- if name != ""
81
+ if name != nil
82
82
  " it \"responds to #{method.upcase} /#{branch_name}/#{name}\" do\n" \
83
83
  " #{method} \"/#{branch_name}/#{name}\"\n" \
84
84
  " expect(last_response.status).to eq(200)\n" \
@@ -158,8 +158,7 @@ class Roda
158
158
  end
159
159
 
160
160
  def parse_route_string(route_str)
161
- name, method = route_str.split(":", 2)
162
- method ||= "get"
161
+ method, name = route_str.split(":", 2)
163
162
  [method, name]
164
163
  end
165
164
 
@@ -1,47 +1,66 @@
1
1
  # Project Code Generation Rules
2
2
 
3
3
  ## Core Stack
4
+
4
5
  - **Web Framework**: Roda (STRICT: Do NOT use Rails, ActionController, or Sinatra conventions).
5
6
  - **No Rails Magic:** Do not use `ActiveSupport` methods (like `.present?` or `.blank?`) unless the gem is explicitly in the Gemfile.<% if context.database %>
6
7
  - **ORM**: Sequel (STRICT: Do NOT use ActiveRecord. Use Sequel Models, Datasets, and Migrations).<% end %>
7
8
  - **Autoloader**: Zeitwerk (Do NOT manually `require` files located in the `app/` directory. Only require standard libraries or gems).<% if context.fullstack? %>
8
9
  - **Frontend**: esbuild + ERB (Fullstack mode).<% end %>
9
10
 
10
- ## Code Style & Conventions
11
+ ## Code Style & Conventions<%= i = 0 %>
12
+
13
+ ### <%= i=i+1 %>. Types
11
14
 
12
- ### 1. Types
13
15
  - Rely on standard Ruby 3.x patterns. Use explicit YARD docs for method signatures.
14
16
 
15
- ### 2. Routing (Roda)
17
+ <% if context.fullstack? %>### <%= i=i+1 %>. Views & Presentation
18
+
19
+ - ERB templates go in `app/views/`.
20
+ - The `view` method inside a route block will match the hash branch to find the view path location:
21
+ - For `hash_branch "foo/bar", "zas" do |r|`, calling `view('something')` will search an erb file in "views/foo/bar/zas/something.erb".
22
+ - For `hash_branch "zas" do |r|`, calling `view('something')` will search an erb file in "views/zas/something.erb".
23
+
24
+ <% end %>### <%= i=i+1 %>. Routing
25
+
16
26
  - The main app resides in `app/[project_name].rb`.
17
27
  - Sub-routes MUST be implemented using Roda **Hash Branches** (`hash_branches` plugin) and placed in `app/routes/`.
18
- - Do not create deep routing blocks. Use Roda's tree routing efficiently (`r.on`, `r.is`, `r.get`, `r.post`).<% if context.database %>
28
+ - **Strict Segment Limit per Branch:** Each hash branch must contain only **one** additional route segment and only **one** CRUD. Do not create deep routing blocks, examples:
29
+ - **Allowed** inside `hash_branch "foo" do |r|`: Handling `GET "foo/bar"`, `POST "foo/bar"`, `GET "foo/something"`, UPDATE `foo/[id]/bar`, GET `foo/[id]/bar` or `GET "foo"`.
30
+ - **FORBIDDEN** inside `hash_branch "foo" do |r|`: Handling deeper segments like `GET "foo/bar/zas"` or `GET "foo/resource/[id]/edit"`.
31
+ - **Solution for Deep Routes:** For deeper paths, you MUST create a new, nested hash branch (e.g., `hash_branch "foo", "bar" do |r|`), in a new nested directory like "app/routes/foo/bar" with views (if any) inside a new view directory like "views/foo/bar".
32
+ - Use Roda's tree routing efficiently (`r.on`, `r.is`, `r.get`, `r.post`).
33
+ - You **MUST** use the `bin/roda g routes` generator for create new route files, examples:
34
+ - `bin/roda g routes branch/name get:foo post:bar` creates a file containing `GET "branch/name/foo"` and `POST "branch/name/bar"` routes.
35
+ - `bin/roda g routes branch_name get post delete:foo` creates a file containing `GET "branch_name"`, `POST "branch_name"` and `DELETE "branch_name/foo"` routes.<% if context.database %>
36
+
37
+ ### <%= i=i+1 %>. Database & Models (Sequel)
19
38
 
20
- ### 3. Database & Models (Sequel)
21
39
  - Models reside in `app/models/`.
22
40
  - Migrations reside in `db/migrations/` and MUST use sequential numbering (e.g., `001_...`).
41
+ - Seeds reside in db/migrations/seeds.rb.
23
42
  - When writing database queries, use Sequel's dataset methods (e.g., `where`, `select`, `exclude`, `join`). Do not use string interpolation for SQL queries.
24
43
 
25
- <% end %><% if context.fullstack? %>### 4. Views & Presentation
26
- - ERB templates go in `app/views/`.
44
+ <% end %>### <%= i=i+1 %>. Testing
27
45
 
28
- <% end %>### 5. Testing
29
46
  - Specs reside in `spec/app/`.
30
47
  - Use `rack-test` for route testing.
31
48
  - Ensure database transactions are rolled back after each test block.
32
49
  - Mirror the file structure of `app/` inside `spec/app/` (e.g., `app/models/user.rb` -> `spec/app/models/user_spec.rb`).
50
+ - Each route **MUST** have tests for each behavior.
51
+ - Each model custom public method **MUST** have tests.
52
+
53
+ ### <%= i=i+1 %>. Config
33
54
 
34
- ### 6. Boot Sequence & Initialization
35
- - **`boot.rb`**: The absolute starting point. It sets up `Bundler`, boots `Zeitwerk` for autoloading the `app/` directory, and loads service providers from `app/config/providers/`.
55
+ - **STRICT:** Config values and ENV **MUST** be centralized in `app/config/config.rb`.
56
+ - External tools, gems or services that need a single initialization or/and specific configuration reside in `app/config/providers/*`.
57
+
58
+ ### <%= i=i+1 %>. Boot Sequence & Initialization
59
+
60
+ - **`boot.rb`**: The absolute starting point. It sets up `Bundler`, global constants, boots `Zeitwerk` for autoloading the `app/` directory, and loads tools, gems or service providers from `app/config/providers/`.
36
61
  - **`config.ru`**: The Rack entrypoint. It defines middleware (like `Rack::LiveReload` in development) and mounts the primary Roda application class defined in `app/[project_name].rb`.
37
62
 
38
- ### 7. Tooling
39
- - Do NOT run `bundle exec rake` for scaffolding/servers. The project uses a custom CLI: `bin/roda`. Suggest commands using `bin/roda` (e.g., generators, running the server).
63
+ ### <%= i=i+1 %>. Tooling
40
64
 
41
- #### Generators
65
+ - Do NOT run `bundle exec rake` for scaffolding/servers. The project uses a custom CLI: `bin/roda`.
42
66
  - To maintain consistency and avoid manual boilerplate, the project uses custom generators for scaffolding new features. These automatically hook into Zeitwerk's expectations, Sequel's DSL, and Roda's Hash Branches.
43
- - **`bin/roda g routes <branch> [options]`**: Scaffolds a Roda hash branch file in `app/routes/`, matching spec files, and ERB views (for GET routes). Supports nested paths (e.g., `api/v1`) and bare verbs (e.g., `books :get :post`).<% if context.database %>
44
- - **`bin/roda g model <name> [fields]`**: Generates a Sequel ORM model class, a matching model spec, and a timestamped Sequel migration. Supports namespacing (`Admin/User`) and auto-pluralizes table names.
45
- - **`bin/roda g migration <name> [fields]`**: Creates a timestamped Sequel migration. It automatically detects intent from the name (e.g., `add_status_to_users` generates the `alter_table` block) and maps Rails-like field types (e.g., `user:references`, `body:text`) to Sequel schema methods.
46
- <% end %>- **`bin/roda g service <type> <name>`**: Scaffolds a class or module service in `app/services/` and a matching spec. Defaults to `class` if type is omitted.
47
-
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Roda
4
4
  module Project
5
- VERSION = "0.1.16"
5
+ VERSION = "0.1.17"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-project
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique F. Teixeira