mk_framework 0.2.0 → 0.2.1

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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mk_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Canessa
@@ -91,32 +91,52 @@ dependencies:
91
91
  version: '2'
92
92
  description: Resource routing, controllers, and response handlers with optional Sequel
93
93
  persistence.
94
- executables: []
94
+ executables:
95
+ - mk_frame_init
95
96
  extensions: []
96
97
  extra_rdoc_files: []
97
98
  files:
98
99
  - CHANGELOG.md
99
100
  - LICENSE
100
101
  - README.md
102
+ - bin/mk_frame_init
101
103
  - docs/deployment.md
102
104
  - docs/routing.md
103
- - docs/upgrading.md
104
105
  - lib/mk_framework.rb
105
106
  - lib/mk_framework/application.rb
106
107
  - lib/mk_framework/controller.rb
107
108
  - lib/mk_framework/errors.rb
109
+ - lib/mk_framework/generator.rb
110
+ - lib/mk_framework/generator/cli.rb
111
+ - lib/mk_framework/generator/configuration.rb
112
+ - lib/mk_framework/generator/options.rb
113
+ - lib/mk_framework/generator/project.rb
114
+ - lib/mk_framework/generator/tasks.rb
115
+ - lib/mk_framework/generator/templates/Gemfile.erb
116
+ - lib/mk_framework/generator/templates/README.md.erb
117
+ - lib/mk_framework/generator/templates/Rakefile.erb
118
+ - lib/mk_framework/generator/templates/app.rb.erb
119
+ - lib/mk_framework/generator/templates/config.ru.erb
120
+ - lib/mk_framework/generator/templates/controller.rb.erb
121
+ - lib/mk_framework/generator/templates/database.rb.erb
122
+ - lib/mk_framework/generator/templates/gitignore.erb
123
+ - lib/mk_framework/generator/templates/handler.rb.erb
124
+ - lib/mk_framework/generator/templates/migration.rb.erb
125
+ - lib/mk_framework/generator/templates/model.rb.erb
126
+ - lib/mk_framework/generator/templates/request_spec.rb.erb
127
+ - lib/mk_framework/generator/templates/spec_helper.rb.erb
108
128
  - lib/mk_framework/request.rb
109
129
  - lib/mk_framework/router.rb
110
130
  - lib/mk_framework/sequel.rb
111
131
  - lib/mk_framework/testing.rb
112
132
  - lib/mk_framework/version.rb
113
- homepage: https://github.com/makevoid/mk_framework2
133
+ homepage: https://github.com/makevoid/mk_framework
114
134
  licenses:
115
135
  - MIT
116
136
  metadata:
117
137
  rubygems_mfa_required: 'true'
118
- source_code_uri: https://github.com/makevoid/mk_framework2
119
- changelog_uri: https://github.com/makevoid/mk_framework2/blob/main/CHANGELOG.md
138
+ source_code_uri: https://github.com/makevoid/mk_framework
139
+ changelog_uri: https://github.com/makevoid/mk_framework/blob/main/CHANGELOG.md
120
140
  rdoc_options: []
121
141
  require_paths:
122
142
  - lib
data/docs/upgrading.md DELETED
@@ -1,124 +0,0 @@
1
- # Upgrading from the prototype
2
-
3
- 0.2.0 changes the Ruby API while retaining the original POST mutation URLs by
4
- default. Upgrade application code before using the new gem. The six samples have
5
- already been migrated.
6
-
7
- ## Application boot and class names
8
-
9
- Place models, controllers, handlers, and the app in an application module. In each
10
- file, declare that module explicitly; `require` does not inherit its caller's
11
- lexical namespace. Configure `root: __dir__` and `namespace: YourApp` in the app,
12
- and call `YourApp::App.boot!` after its class definition.
13
-
14
- Models must be loaded before boot. MK loads action files relative to the configured
15
- root and resolves action classes there. `boot!` validates and freezes the app;
16
- calling `app` before boot is an error. Configure middleware and plugins beforehand.
17
- Restart the process to pick up source changes.
18
-
19
- The samples now expose `SampleApp1::App` through `SampleApp6::App` instead of global
20
- `TodoApp`, `BlogApp`, `KanbanApp`, and `WeatherApp` classes. Their model datasets are
21
- explicit, so multiple sample apps can coexist without sharing constants or data.
22
-
23
- ## Automatic action persistence and raw handler data
24
-
25
- Previously, handlers interpreted class-name suffixes and saved/deleted the object
26
- returned by a controller. Remove handler `success`/`error` registration blocks.
27
- Controllers return the prepared record; framework dispatch persists it according
28
- to the registered action and converts it to raw attributes before the handler:
29
-
30
- ```ruby
31
- # Controller
32
- route do |r|
33
- Post.new(r.input.permit(title: String))
34
- end
35
-
36
- # Handler
37
- handler do |r|
38
- r.response.status = 201
39
- {post: fields(model, :id, :title)}
40
- end
41
- ```
42
-
43
- Require `mk_framework/sequel` for this lifecycle. Sequel is optional and must be
44
- listed in your application's Gemfile. Create/update results receive `save` then
45
- `values`; delete results receive `destroy` then `values`; show/index results are
46
- converted without writes. Remove explicit `persist`, `save`, and `destroy` calls
47
- from standard controllers to avoid duplicate writes. For explicit multi-record
48
- transactions, return raw data after completing the writes. Custom actions do not
49
- automatically persist records.
50
-
51
- Handlers receive raw hashes/arrays, including materialized nested results. Replace
52
- model attribute/association methods with hash access and allowlist filtering.
53
- Select associations in controllers. A handler does not query or write under any
54
- action name. Validation uses 422 for
55
- both create and update; expected constraint conflicts use 409. Unexpected failures
56
- are sanitized 500s. Deliberate `MK::Error` messages are public.
57
-
58
- The old `route` declaration in a handler remains an alias for `handler`, but it
59
- does not move persistence into handlers. Handlers return Hash/Array responses rather
60
- than calling `to_json`. For an empty success, use `r.halt(204)` in the handler.
61
-
62
- ## Resource declarations
63
-
64
- Replace `register_nested_resource` with a resource tree:
65
-
66
- ```ruby
67
- resource_routes do
68
- resources :posts do
69
- resources :comments
70
- end
71
- # Optional compatibility URLs for the old shallow member endpoints:
72
- resources :comments, only: %i[show update delete]
73
- end
74
- ```
75
-
76
- This exposes fully nested CRUD plus the explicitly requested shallow members.
77
- For exclusively shallow members, instead use `resources :comments, shallow: true`
78
- inside the parent. There are no implicit parentless comment collections.
79
-
80
- Use `r.path_params` for ancestor and member IDs. Existing `r.params['id']` remains
81
- supported, but `r.input` deliberately contains only query/body input. `r.params`
82
- gives URL IDs precedence. Scope all nested member lookups through their parent.
83
-
84
- PATCH, PUT, and DELETE now work. POST update/delete aliases remain on by default;
85
- turn them off using `configure legacy_post_routes: false` when clients migrate.
86
-
87
- ## Database migration
88
-
89
- Server boot no longer creates tables. On a new database, run the sample's
90
- `bundle exec rake db:migrate` before loading its app. Tests use their own in-memory
91
- databases and run migrations there.
92
-
93
- Do not run the initial migration blindly against a populated prototype database:
94
- the existing tables will cause it to fail rather than be silently adopted or
95
- replaced. Back up that database, compare its schema with `db/migrations/001_initial.rb`,
96
- and write an application-specific upgrade migration or import into a freshly
97
- migrated database. Backfill null timestamps and missing defaults before adding
98
- the new constraints. Mark the initial migration applied only after confirming
99
- schema equivalence. No existing database is automatically altered by this upgrade.
100
-
101
- ## Responses and clients
102
-
103
- Lists are bounded to 25 records by default; use `limit` and `offset`. Maximum limit
104
- is 100 and maximum offset is 10,000. Nested comments included in parent show
105
- responses use the same bounds. Adapt clients that previously expected every row.
106
-
107
- The weather API uses `OPENWEATHERMAP_API_KEY`, not a file in the user's home. Its
108
- response field is now `forecast`, containing eight three-hour periods, replacing
109
- the inaccurate `hourly_forecast` field. Times include a timezone. Upstream failures
110
- are sanitized 502 responses; an unknown location is 404; a missing key is 503.
111
-
112
- Missing-resource responses consistently use an `error` field. Unexpected error
113
- responses also include a request ID. Do not depend on internal exception messages.
114
-
115
- ## Tests and dependencies
116
-
117
- Use `bundle exec rake` at the repository root to test the framework and every
118
- sample in isolated processes. Child failures fail the aggregate task. Sample tests
119
- force `RACK_ENV=test`; they do not open development databases or `DATABASE_URL`.
120
-
121
- Install the updated bundles with Ruby 3.2 or later and the locked Bundler version.
122
- The lockfiles include updates to Roda, Rack, Sequel, SQLite3, Puma, and test tools.
123
- Puma moved from 6.x to 8.x; review your own server configuration when upgrading.
124
- See `docs/deployment.md` for deployment and release checks.