lotusrb 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -3
- data/FEATURES.md +94 -0
- data/README.md +73 -22
- data/lib/lotus/cli.rb +24 -5
- data/lib/lotus/commands/db/console.rb +54 -0
- data/lib/lotus/commands/db.rb +27 -0
- data/lib/lotus/commands/generate.rb +70 -0
- data/lib/lotus/config/cookies.rb +47 -0
- data/lib/lotus/config/security.rb +58 -0
- data/lib/lotus/configuration.rb +65 -24
- data/lib/lotus/environment.rb +3 -1
- data/lib/lotus/generators/action/action.rb.tt +8 -0
- data/lib/lotus/generators/action/action_spec.minitest.tt +12 -0
- data/lib/lotus/generators/action/action_spec.rspec.tt +12 -0
- data/lib/lotus/generators/action/template.tt +0 -0
- data/lib/lotus/generators/action/view.rb.tt +5 -0
- data/lib/lotus/generators/action/view_spec.minitest.tt +12 -0
- data/lib/lotus/generators/action/view_spec.rspec.tt +12 -0
- data/lib/lotus/generators/action.rb +149 -0
- data/lib/lotus/generators/application/container/Gemfile.tt +7 -2
- data/lib/lotus/generators/application/container/config/.env.development.tt +1 -1
- data/lib/lotus/generators/application/container/config/.env.test.tt +1 -1
- data/lib/lotus/generators/application/container/gitignore.tt +2 -0
- data/lib/lotus/generators/application/container/lib/app_name.rb.tt +4 -2
- data/lib/lotus/generators/application/container/lotusrc.tt +3 -0
- data/lib/lotus/generators/application/container.rb +78 -8
- data/lib/lotus/generators/slice/application.rb.tt +63 -11
- data/lib/lotus/generators/slice/config/mapping.rb.tt +4 -1
- data/lib/lotus/loader.rb +10 -2
- data/lib/lotus/lotusrc.rb +146 -0
- data/lib/lotus/middleware.rb +2 -2
- data/lib/lotus/routes.rb +62 -6
- data/lib/lotus/version.rb +1 -1
- data/lotusrb.gemspec +6 -5
- metadata +41 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b55d7a5c85223bdd933991a7dd042bc9319346c4
|
4
|
+
data.tar.gz: 64b71e0266d64d7ffcdf65af2f7d6309432dc673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8fbd473ccaedb272a101587f25ed494cc1a6bd43d3dbd89971baef2520293398358153dc0d5d231fe2dd8ab4f06fcf50b242990b0ae95ec48064e2cf06d52e3
|
7
|
+
data.tar.gz: 2365f2e8fb616a841d670adc1d29a59fc1004dc1e05fc9039ff9da52349407aecdbf245b392c9eb0bc6e8a21a061d8262f5115948540f5b34f221b7271a45955
|
data/CHANGELOG.md
CHANGED
@@ -1,20 +1,37 @@
|
|
1
1
|
# Lotus
|
2
2
|
A complete web framework for Ruby
|
3
3
|
|
4
|
+
## v0.3.0 - 2015-03-23
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Introduced action generator. Eg. `bundle exec lotus generate action web dashboard#index`
|
7
|
+
- [Alfonso Uceda Pompa] Allow to specify default coookies options in application configuration. Eg. `cookies true, { domain: 'lotusrb.org' }`
|
8
|
+
- [Tom Kadwill] Include `Lotus::Helpers` in views.
|
9
|
+
- [Linus Pettersson] Allow to specify `--database` CLI option when generate a new application. Eg. `lotus new bookshelf --database=postgresql`
|
10
|
+
- [Linus Pettersson] Initialize a Git repository when generating a new application
|
11
|
+
- [Alfonso Uceda Pompa] Produce `.lotusrc` when generating a new application
|
12
|
+
- [Alfonso Uceda Pompa] Security HTTP headers. `X-Frame-Options` and `Content-Security-Policy` are now enabled by default.
|
13
|
+
- [Linus Pettersson] Database console. Run with `bundle exec lotus db console`
|
14
|
+
- [Luca Guidi] Dynamic finders for relative and absolute routes. It implements method missing: `Web::Routes.home_path` will resolve to `Web::Routes.path(:home)`.
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
– [Alfonso Uceda Pompa] Cookies will send `HttpOnly` by default. This is for security reasons.
|
18
|
+
- [Jan Lelis] Enable `templates` configuration for new generated apps
|
19
|
+
- [Mark Connell] Change SQLite file extension from `.db` to `.sqlite3`
|
20
|
+
|
4
21
|
## v0.2.1 - 2015-02-06
|
5
22
|
### Added
|
6
|
-
- [Huy
|
23
|
+
- [Huy Đỗ] Introduced `Lotus::Logger`
|
7
24
|
- [Jimmy Zhang] `lotus new` accepts a `--path` argument
|
8
25
|
- [Jimmy Zhang] Application generator for the current directory (`lotus new .`). This is useful to provide a web deliverable for existing Ruby gems.
|
9
26
|
- [Trung Lê] Add example mapping file for application generator: `lib/config/mapping.rb`
|
10
|
-
- [
|
27
|
+
- [Hiếu Nguyễn] RSpec support for application generator: `--test=rspec` or `--test=minitest` (default)
|
11
28
|
|
12
29
|
### Fixed
|
13
30
|
- [Luca Guidi] `lotus version` to previx `v` (eg `v0.2.1`)
|
14
31
|
- [Rob Yurkowski] Ensure application name doesn't contain special or forbidden characters
|
15
32
|
- [Luca Guidi] Ensure all the applications are loaded in console
|
16
33
|
- [Trung Lê] Container architecture: preload only `lib/<appname>/**/*.rb`
|
17
|
-
- [
|
34
|
+
- [Hiếu Nguyễn] Fixed `lotus new` to print usage when application name isn't provided
|
18
35
|
|
19
36
|
## v0.2.0 - 2014-06-23
|
20
37
|
### Added
|
data/FEATURES.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Lotus
|
2
|
+
### A complete web framework for Ruby
|
3
|
+
|
4
|
+
## Features
|
5
|
+
|
6
|
+
## v0.3.0 - 2015-03-23
|
7
|
+
|
8
|
+
- CLI: `lotus generate action web dashboard#index`. It generates an action, a view, a template, a route and related unit test files.
|
9
|
+
- CLI: `lotus db console`. It starts a database REPL.
|
10
|
+
- Full featured HTML5 markup generator for views (Eg. `html.div { p "Hello World" }`)
|
11
|
+
- Routing helpers in views and templates (Eg. `routes.home_path`).
|
12
|
+
- `lotus new` supports `--database` (Eg. `lotus new bookshelf --database=postgresql`).
|
13
|
+
- Initialize a Git repository when generate a new application
|
14
|
+
- Security: XSS (Cross Site Scripting) protections
|
15
|
+
- Security: Clickhijacking protection
|
16
|
+
- Security: Cookies are set as `HttpOnly` by default.
|
17
|
+
- Security: enable by default `X-Frame-Options` and `Content-Security-Policy` HTTP headers for new generated applications.
|
18
|
+
- Security: auto-escape output of presenters.
|
19
|
+
- Security: auto-escape output of virtual an concrete view methods.
|
20
|
+
- Security: view and template helpers for HTML, HTML attributes and URL escape. It's based on OWASP/ESAPI recommendations.
|
21
|
+
- Access nested action params with a safe API (`params.get('address.city')`).
|
22
|
+
- Interactors (aka Service Objects)
|
23
|
+
- Database transactions
|
24
|
+
|
25
|
+
## v0.2.1 - 2015-02-06
|
26
|
+
|
27
|
+
- Allow entities to include validations.
|
28
|
+
- `lotus new .` to generate a Lotus application for an existing code base (Eg. a gem that needs a web UI).
|
29
|
+
- `lotus new` supports `--path` (for destination directory), `--test` (to generate Minitest or RSpec boilerplate).
|
30
|
+
- Lotus logger
|
31
|
+
|
32
|
+
## v0.2.0 - 2014-12-23
|
33
|
+
|
34
|
+
- Support Minitest as default testing framework (`bundle exec rake` runs the entire test suite of an application).
|
35
|
+
- Support for _Method Override_ technique.
|
36
|
+
- Custom templates for non successful responses (Eg. `404.html.erb`).
|
37
|
+
- Support distinct `.env` files for each Lotus environment.
|
38
|
+
- Allow to configure multiple applications and handle Lotus environments accordingly.
|
39
|
+
- Allow to configure middleware stack, routes, database mapping and adapter for each application.
|
40
|
+
- Show a welcome page with instructions for new generated apps.
|
41
|
+
- CLI: `lotus routes`. It prints all the routes available for all the applications.
|
42
|
+
- CLI: `lotus new`. It generates a new application which can run multiple Lotus applications (_Container_ architecture).
|
43
|
+
- CLI: `lotus console`. It starts a Ruby REPL. It supports IRB (default), Pry and Ripl.
|
44
|
+
- CLI: `lotus server`. It starts a web server that supports code reloading. It supports all the Rack web servers (default: WEBRick).
|
45
|
+
- Database adapters: File system (default for new apps)
|
46
|
+
- Allow to share code for all the views and actions of an application
|
47
|
+
- Reusable validations framework (mixin). It supports: coercions and presence, format, acceptance, size, inclusion, exclusion, confirmation validations.
|
48
|
+
- Default Content-Type and Charset for responses
|
49
|
+
- Whitelist accepted MIME Types
|
50
|
+
- Custom exception handlers for actions
|
51
|
+
- Unique identifier for incoming HTTP requests
|
52
|
+
- Nested action params
|
53
|
+
- Action params _indifferent access_, whitelisting, validations and coercions
|
54
|
+
- HTTP caching (`Cache-Control`, `Last-Modified`, ETAG, Conditional GET, expires)
|
55
|
+
- JSON body parser for non-GET HTTP requests
|
56
|
+
- Routes inspector for CLI
|
57
|
+
|
58
|
+
## v0.1.0 - 2014-06-23
|
59
|
+
|
60
|
+
- Run multiple Lotus applications in the same Ruby process
|
61
|
+
- Serve static files
|
62
|
+
- Render default pages for non successful responses (404, 500, etc.)
|
63
|
+
- Support multiple Lotus environments (development, test and production)
|
64
|
+
- Full stack applications
|
65
|
+
- Data mapper
|
66
|
+
- Database adapters: Memory and SQL
|
67
|
+
- Reusable scopes for repositories
|
68
|
+
- Repositories
|
69
|
+
- Entities
|
70
|
+
- Custom rendering implementation via `#render` override in views
|
71
|
+
- Render partials and templates
|
72
|
+
- Presenters
|
73
|
+
- Layouts
|
74
|
+
- Views are able to handle multiple MIME Types according to the defined templates
|
75
|
+
- Support for all the most common template engines for Ruby. Including ERb, Slim, HAML, etc.
|
76
|
+
- Basic view rendering with templates
|
77
|
+
- Bypass rendering by setting a response body in actions (`self.body = "Hello"`)
|
78
|
+
- Single actions are able to mount Rack middleware
|
79
|
+
- Automatic MIME Type handling for request and responses
|
80
|
+
- HTTP sessions
|
81
|
+
- HTTP cookies
|
82
|
+
- HTTP redirect
|
83
|
+
- Action before/after callbacks
|
84
|
+
- Handle exceptions with HTTP statuses
|
85
|
+
- Action exposures, to expose a payload to pass to the other application layers
|
86
|
+
- Actions compatible with Rack
|
87
|
+
- Mount Rack applications
|
88
|
+
- Nested route namespaces
|
89
|
+
- RESTful resource(s), including collection and member actions
|
90
|
+
- Named routes, routes constraints, variables, catch-all
|
91
|
+
- Compatibility with Lotus::Controller
|
92
|
+
- HTTP redirect from the router
|
93
|
+
- HTTP routing compatible with Rack
|
94
|
+
- Thread safety
|
data/README.md
CHANGED
@@ -4,17 +4,19 @@ A complete web framework for Ruby
|
|
4
4
|
|
5
5
|
## Frameworks
|
6
6
|
|
7
|
-
Lotus combines
|
7
|
+
Lotus combines small yet powerful frameworks:
|
8
8
|
|
9
9
|
* [**Lotus::Utils**](https://github.com/lotus/utils) - Ruby core extentions and class utilities
|
10
10
|
* [**Lotus::Router**](https://github.com/lotus/router) - Rack compatible HTTP router for Ruby
|
11
11
|
* [**Lotus::Validations**](https://github.com/lotus/validations) - Validation mixin for Ruby objects
|
12
|
+
* [**Lotus::Helpers**](https://github.com/lotus/helpers) - View helpers for Ruby applications
|
12
13
|
* [**Lotus::Model**](https://github.com/lotus/model) - Persistence with entities, repositories and data mapper
|
13
14
|
* [**Lotus::View**](https://github.com/lotus/view) - Presentation with a separation between views and templates
|
15
|
+
* [**Lotus::Helpers**](https://github.com/lotus/helpers) - Presentation helpers for views
|
14
16
|
* [**Lotus::Controller**](https://github.com/lotus/controller) - Full featured, fast and testable actions for Rack
|
15
17
|
|
16
|
-
|
17
|
-
If
|
18
|
+
These components are designed to be used independently or together in a Lotus application.
|
19
|
+
If you aren't familiar with them, please take time to go through their READMEs.
|
18
20
|
|
19
21
|
## Status
|
20
22
|
|
@@ -32,7 +34,8 @@ If your aren't familiar with them, please take time to go through their READMEs.
|
|
32
34
|
* API Doc: http://rdoc.info/gems/lotusrb
|
33
35
|
* Bugs/Issues: https://github.com/lotus/lotus/issues
|
34
36
|
* Support: http://stackoverflow.com/questions/tagged/lotus-ruby
|
35
|
-
*
|
37
|
+
* Forum: https://discuss.lotusrb.org
|
38
|
+
* Chat: http://chat.lotusrb.org
|
36
39
|
|
37
40
|
## Rubies
|
38
41
|
|
@@ -62,13 +65,13 @@ Developers can arrange the layout of their projects as they prefer.
|
|
62
65
|
There is a suggested architecture that can be easily changed with a few settings.
|
63
66
|
|
64
67
|
Lotus encourages the use of Ruby namespaces. This is based on the experience of working on dozens of projects.
|
65
|
-
By using Ruby namespaces, as your code grows it can be split with less effort. In other words, Lotus is providing gentle guidance for **
|
68
|
+
By using Ruby namespaces, as your code grows it can be split with less effort. In other words, Lotus is providing gentle guidance for **avoiding monolithic applications**.
|
66
69
|
|
67
70
|
Lotus has a smart **mechanism of duplication of its frameworks**.
|
68
71
|
It allows multiple copies of the framework and multiple applications to run in the **same Ruby process**.
|
69
|
-
In other words, Lotus applications are ready to be split into smaller parts but these parts can coexist in the same heap space.
|
72
|
+
In other words, Lotus applications are ready to be split into smaller parts, but these parts can coexist in the same heap space.
|
70
73
|
|
71
|
-
All this adaptability can be helpful to bend the framework for your advanced
|
74
|
+
All this adaptability can be helpful to bend the framework for your advanced requirements, but we recognize the need for guidance in standard architectures.
|
72
75
|
For this reason Lotus is shipped with code generators.
|
73
76
|
|
74
77
|
|
@@ -76,29 +79,28 @@ For this reason Lotus is shipped with code generators.
|
|
76
79
|
|
77
80
|
**TL;DR: Develop your application like a gem. Implement use cases in `lib/`. Use one or more Lotus applications in `apps/`.**
|
78
81
|
|
79
|
-
This is the default architecture.
|
80
|
-
When your are about to start a new project use it.
|
82
|
+
This is the default architecture. Use it when you are ready to begin a new project.
|
81
83
|
|
82
84
|
The core of this architecture lives in `lib/`, where developers should build features **independently from the delivery mechanism**.
|
83
85
|
|
84
|
-
Imagine you are building a personal finance application, and you have a feature called _"register expense"_
|
86
|
+
Imagine you are building a personal finance application, and you have a feature called _"register expense."_ This functionality involves `Money` and `Expense` Ruby objects and the need for persisting data into a database. You can have those classes living in `lib/pocket/money.rb` and `lib/pocket/expense.rb` and use [Lotus::Model](https://github.com/lotus/model) to persist them.
|
85
87
|
|
86
88
|
It's based on a few simple concepts: **use cases** and **applications**.
|
87
89
|
Use cases (features) should be implemented in `lib/` with a combination of pure objects and the needed Ruby gems.
|
88
|
-
One or more Lotus applications live in `apps/`. They are isolated each other, and depend only on the code in `lib/`.
|
90
|
+
One or more Lotus applications live in `apps/`. They are isolated from each other, and depend only on the code in `lib/`.
|
89
91
|
|
90
|
-
Each
|
92
|
+
Each application should serve only one purpose: user-facing web application, administrative backend, JSON API, metrics dashboard, etc.
|
91
93
|
|
92
94
|
This architecture has important advantages:
|
93
95
|
|
94
|
-
* **Code reusability.** You can consume a feature from the Web UI or from a HTTP API. Each
|
96
|
+
* **Code reusability.** You can consume a feature from the Web UI or from a HTTP API. Each can be a different Lotus application or simple Rack-based endpoints.
|
95
97
|
* **Decoupled components.** The core of your application depends only on a few gems and it doesn't need to worry about the Web/HTTP/Console/Background jobs.
|
96
|
-
* **Applications are built like
|
97
|
-
* **Avoid monoliths**. Each Lotus application under `apps/` is a candidate for later
|
98
|
+
* **Applications are built like gems.** This eases the process of packaging and sharing them among projects, without the need for many dependencies.
|
99
|
+
* **Avoid monoliths**. Each Lotus application under `apps/` is a candidate for later extraction into a separated [_microservice_](http://martinfowler.com/articles/microservices.html).
|
98
100
|
|
99
|
-
The last point is crucial. In the early days of a new project is
|
100
|
-
|
101
|
-
Lotus helps to plan those things ahead of time, but without the burden that is required by those choices, because it
|
101
|
+
The last point is crucial. In the early days of a new project it is convenient to build and deploy all the code together.
|
102
|
+
However, as time passes, it can become nearly impossible to extract sets of cohesive functionalities into separated deliverables.
|
103
|
+
Lotus helps to plan those things ahead of time, but without the burden that is required by those choices, because it supports multiple applications natively.
|
102
104
|
|
103
105
|
Here's the name _**container**_: a Lotus _"shell"_ that can run multiple micro applications in the same process.
|
104
106
|
|
@@ -122,7 +124,7 @@ _upcoming_
|
|
122
124
|
* Lotus expects controllers, actions and views to have a specific pattern (see [Configuration](#configuration) for customizations)
|
123
125
|
* All the commands must be run from the root of the project. If this requirement cannot be satisfied, please hardcode the path with `Configuration#root`.
|
124
126
|
* The template name must reflect the name of the corresponding view: `Bookshelf::Views::Dashboard::Index` for `dashboard/index.html.erb`.
|
125
|
-
* All
|
127
|
+
* All static files are served by the internal Rack middleware stack.
|
126
128
|
* The application expects to find static files under `public/` (see `Configuration#assets`)
|
127
129
|
* If the public folder doesn't exist, it doesn't serve static files.
|
128
130
|
|
@@ -235,7 +237,7 @@ module Bookshelf
|
|
235
237
|
# uri: String, 'file:///db/bookshelf'
|
236
238
|
# 'memory://localhost/bookshelf'
|
237
239
|
# 'sqlite:memory:'
|
238
|
-
# 'sqlite://db/bookshelf.
|
240
|
+
# 'sqlite://db/bookshelf.sqlite3'
|
239
241
|
# 'postgres://localhost/bookshelf'
|
240
242
|
# 'mysql://localhost/bookshelf'
|
241
243
|
#
|
@@ -290,6 +292,22 @@ module Bookshelf
|
|
290
292
|
#
|
291
293
|
serve_assets true
|
292
294
|
|
295
|
+
###########################
|
296
|
+
# SECURITY CONFIGURATIONS #
|
297
|
+
###########################
|
298
|
+
|
299
|
+
# Set a default value for X-Frame-Options HTTP header
|
300
|
+
# Argument: String
|
301
|
+
# Remove this line to disable this feature
|
302
|
+
#
|
303
|
+
security.x_frame_options "DENY"
|
304
|
+
|
305
|
+
# Set a default value for Content-Security-Policy HTTP header
|
306
|
+
# Argument: String
|
307
|
+
# Remove this line to disable this feature
|
308
|
+
#
|
309
|
+
security.content_security_policy "default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'; style-src 'self';"
|
310
|
+
|
293
311
|
#############################
|
294
312
|
# FRAMEWORKS CONFIGURATIONS #
|
295
313
|
#############################
|
@@ -301,7 +319,7 @@ module Bookshelf
|
|
301
319
|
# Argument: Proc
|
302
320
|
#
|
303
321
|
view.prepare do
|
304
|
-
include
|
322
|
+
include Lotus::Helpers # they will be included in all the views
|
305
323
|
end
|
306
324
|
|
307
325
|
# Low level configuration for Lotus::Controller (optional)
|
@@ -344,14 +362,47 @@ It supports **code reloading** feature by default, useful for development purpos
|
|
344
362
|
% bundle exec lotus server
|
345
363
|
```
|
346
364
|
|
365
|
+
### Generators
|
366
|
+
|
367
|
+
#### Action generator
|
368
|
+
|
369
|
+
It generates an **action**, a **view**, a **template**, a **route** and the relative unit tests.
|
370
|
+
|
371
|
+
```shell
|
372
|
+
% bundle exec lotus generate action web dashboard#index
|
373
|
+
```
|
374
|
+
|
375
|
+
The `web` argument is the name of the application under `apps/`.
|
376
|
+
The `dashboard#index` argument is the name of the controller and the name of the action.
|
377
|
+
|
378
|
+
It generates Minitest/RSpec files according to `test` setting in `.lotusrc`.
|
379
|
+
It generates an empty template with the template engine extension (`template`) setting in `.lotusrc`.
|
380
|
+
|
381
|
+
It generates the following files:
|
382
|
+
|
383
|
+
* `apps/web/controllers/dashboard/index.rb`
|
384
|
+
* `spec/web/controllers/dashboard/index_spec.rb`
|
385
|
+
* `apps/web/views/dashboard/index.rb`
|
386
|
+
* `spec/web/views/dashboard/index_spec.rb`
|
387
|
+
* `apps/web/templates/dashboard/index.html.erb` (**empty file**)
|
388
|
+
* Amend `apps/web/config/routes.rb` with a new route
|
389
|
+
|
347
390
|
### Console
|
348
391
|
|
349
|
-
It starts a REPL, by using the engine defined in your `Gemfile`. It defaults to
|
392
|
+
It starts a REPL, by using the engine defined in your `Gemfile`. It defaults to IRB. **Run it from the root of the application**.
|
350
393
|
|
351
394
|
```shell
|
352
395
|
% bundle exec lotus console
|
353
396
|
```
|
354
397
|
|
398
|
+
### Database console
|
399
|
+
|
400
|
+
It starts a database REPL, by looking at your database configuration under `lib/. **Run it from the root of the application**.
|
401
|
+
|
402
|
+
```shell
|
403
|
+
% bundle exec lotus db console
|
404
|
+
```
|
405
|
+
|
355
406
|
It supports **code reloading** via the `reload!` command.
|
356
407
|
|
357
408
|
### Routes
|
data/lib/lotus/cli.rb
CHANGED
@@ -61,12 +61,13 @@ module Lotus
|
|
61
61
|
end
|
62
62
|
|
63
63
|
desc 'new', 'generates a new application'
|
64
|
-
method_option :
|
65
|
-
method_option :
|
66
|
-
method_option :
|
67
|
-
method_option :
|
64
|
+
method_option :database, aliases: '-d', desc: 'application database', type: :string, default: 'filesystem'
|
65
|
+
method_option :architecture, aliases: '-a', desc: 'application architecture', type: :string, default: 'container'
|
66
|
+
method_option :application, desc: 'application name', type: :string, default: 'web'
|
67
|
+
method_option :application_base_url, desc: 'application base url', type: :string, default: '/'
|
68
|
+
method_option :path, desc: 'path', type: :string
|
68
69
|
method_option :test, desc: 'application test framework (rspec/minitest)', type: :string, default: 'minitest'
|
69
|
-
method_option :lotus_head, desc: 'use Lotus HEAD',
|
70
|
+
method_option :lotus_head, desc: 'use Lotus HEAD', type: :boolean, default: false
|
70
71
|
method_option :help, aliases: '-h', desc: 'displays the usage method'
|
71
72
|
|
72
73
|
def new(name = nil)
|
@@ -78,6 +79,24 @@ module Lotus
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
82
|
+
desc 'generate', 'generates a new action'
|
83
|
+
method_option :path, desc: 'applications path', type: :string, default: 'apps'
|
84
|
+
method_option :help, aliases: '-h', desc: 'displays the usage method'
|
85
|
+
|
86
|
+
# @since 0.3.0
|
87
|
+
# @api private
|
88
|
+
def generate(type = nil, app_name = nil, name = nil)
|
89
|
+
if options[:help] || (type.nil? && app_name.nil? && name.nil?)
|
90
|
+
invoke :help, ['generate']
|
91
|
+
else
|
92
|
+
require 'lotus/commands/generate'
|
93
|
+
Lotus::Commands::Generate.new(type, app_name, name, environment, self).start
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
require 'lotus/commands/db'
|
98
|
+
register Lotus::Commands::DB, 'db', 'db [SUBCOMMAND]', 'manage set of DB operations'
|
99
|
+
|
81
100
|
private
|
82
101
|
|
83
102
|
def environment
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'lotus/utils/class'
|
2
|
+
|
3
|
+
module Lotus
|
4
|
+
module Commands
|
5
|
+
class DB
|
6
|
+
class Console
|
7
|
+
attr_reader :name, :env_options, :environment
|
8
|
+
|
9
|
+
def initialize(name, environment)
|
10
|
+
@name = name
|
11
|
+
@environment = environment
|
12
|
+
@env_options = environment.to_options
|
13
|
+
load_config
|
14
|
+
end
|
15
|
+
|
16
|
+
def start
|
17
|
+
exec connection_string
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def config
|
23
|
+
if name
|
24
|
+
app_constant = Lotus::Utils::Class.load_from_pattern!(Lotus::Utils::String.new(name).classify)
|
25
|
+
Lotus::Utils::Class.load_from_pattern!("#{app_constant}::Application").load!
|
26
|
+
Lotus::Utils::Class.load_from_pattern!("#{app_constant}::Model").configuration
|
27
|
+
else
|
28
|
+
Lotus::Model.configuration
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def adapter_config
|
33
|
+
config.adapter_config
|
34
|
+
end
|
35
|
+
|
36
|
+
def mapper
|
37
|
+
config.mapper
|
38
|
+
end
|
39
|
+
|
40
|
+
def adapter_class
|
41
|
+
Lotus::Utils::Class.load_from_pattern!(adapter_config.class_name, Lotus::Model::Adapters)
|
42
|
+
end
|
43
|
+
|
44
|
+
def connection_string
|
45
|
+
adapter_class.new(mapper, adapter_config.uri).connection_string
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_config
|
49
|
+
require @env_options[:env_config]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Lotus
|
2
|
+
module Commands
|
3
|
+
class DB < Thor
|
4
|
+
namespace :db
|
5
|
+
|
6
|
+
desc 'db console', 'start DB console'
|
7
|
+
|
8
|
+
desc 'console', 'start DB console'
|
9
|
+
method_option :environment, desc: 'path to environment configuration (config/environment.rb)'
|
10
|
+
|
11
|
+
def console(name = nil)
|
12
|
+
if options[:help]
|
13
|
+
invoke :help, ['console']
|
14
|
+
else
|
15
|
+
require 'lotus/commands/db/console'
|
16
|
+
Lotus::Commands::DB::Console.new(name, environment).start
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def environment
|
23
|
+
Lotus::Environment.new(options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'lotus/utils/string'
|
3
|
+
require 'lotus/utils/class'
|
4
|
+
|
5
|
+
module Lotus
|
6
|
+
module Commands
|
7
|
+
# @since 0.3.0
|
8
|
+
# @api private
|
9
|
+
class Generate
|
10
|
+
# @since 0.3.0
|
11
|
+
# @api private
|
12
|
+
GENERATORS_NAMESPACE = "Lotus::Generators::%s".freeze
|
13
|
+
|
14
|
+
# @since 0.3.0
|
15
|
+
# @api private
|
16
|
+
class Error < ::StandardError
|
17
|
+
end
|
18
|
+
|
19
|
+
# @since 0.3.0
|
20
|
+
# @api private
|
21
|
+
attr_reader :cli, :source, :target, :app, :app_name, :name, :options
|
22
|
+
|
23
|
+
# @since 0.3.0
|
24
|
+
# @api private
|
25
|
+
def initialize(type, app_name, name, env, cli)
|
26
|
+
@cli = cli
|
27
|
+
@options = env.to_options.merge(cli.options)
|
28
|
+
|
29
|
+
@app_name = app_name
|
30
|
+
@app = Utils::String.new(@app_name).classify
|
31
|
+
|
32
|
+
@name = name
|
33
|
+
@type = type
|
34
|
+
|
35
|
+
@source = Pathname.new(::File.dirname(__FILE__) + "/../generators/#{ @type }/").realpath
|
36
|
+
@target = Pathname.pwd.realpath
|
37
|
+
end
|
38
|
+
|
39
|
+
# @since 0.3.0
|
40
|
+
# @api private
|
41
|
+
def start
|
42
|
+
generator.start
|
43
|
+
rescue Error => e
|
44
|
+
puts e.message
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
# @since 0.3.0
|
49
|
+
# @api private
|
50
|
+
def app_root
|
51
|
+
@app_root ||= Pathname.new([@options[:path], @app_name].join(::File::SEPARATOR))
|
52
|
+
end
|
53
|
+
|
54
|
+
# @since 0.3.0
|
55
|
+
# @api private
|
56
|
+
def spec_root
|
57
|
+
@spec_root ||= Pathname.new('spec')
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
# @since 0.3.0
|
62
|
+
# @api private
|
63
|
+
def generator
|
64
|
+
require "lotus/generators/#{ @type }"
|
65
|
+
class_name = Utils::String.new(@type).classify
|
66
|
+
Utils::Class.load!(GENERATORS_NAMESPACE % class_name).new(self)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Lotus
|
2
|
+
module Config
|
3
|
+
# Cookies configuration
|
4
|
+
#
|
5
|
+
# @since 0.3.0
|
6
|
+
# @api private
|
7
|
+
class Cookies
|
8
|
+
|
9
|
+
# Return the routes for this application
|
10
|
+
#
|
11
|
+
# @return [Hash] options for cookies
|
12
|
+
#
|
13
|
+
# @since 0.3.0
|
14
|
+
# @api private
|
15
|
+
attr_reader :default_options
|
16
|
+
|
17
|
+
# Cookies configuration
|
18
|
+
#
|
19
|
+
# httponly option enabled by default.
|
20
|
+
# Prevent attackers to steal cookies via JavaScript,
|
21
|
+
# Eg. alert(document.cookie) will fail
|
22
|
+
#
|
23
|
+
# @param enabled [TrueClass, FalseClass] enable cookies
|
24
|
+
# @param options [Hash] optional cookies options
|
25
|
+
#
|
26
|
+
# @since 0.3.0
|
27
|
+
# @api private
|
28
|
+
#
|
29
|
+
# @see https://github.com/rack/rack/blob/master/lib/rack/utils.rb #set_cookie_header!
|
30
|
+
# @see https://www.owasp.org/index.php/HttpOnly
|
31
|
+
def initialize(enabled = false, options = {})
|
32
|
+
@enabled = enabled
|
33
|
+
@default_options = { httponly: true }.merge(options)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return if cookies are enabled
|
37
|
+
#
|
38
|
+
# @return [TrueClass, FalseClass] enabled cookies
|
39
|
+
#
|
40
|
+
# @since 0.3.0
|
41
|
+
# @api private
|
42
|
+
def enabled?
|
43
|
+
!!@enabled
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Lotus
|
2
|
+
module Config
|
3
|
+
# Security policies are stored here.
|
4
|
+
#
|
5
|
+
# @since 0.3.0
|
6
|
+
class Security
|
7
|
+
# @since 0.3.0
|
8
|
+
# @api private
|
9
|
+
#
|
10
|
+
# @see Lotus::Loader#_configure_controller_framework!
|
11
|
+
X_FRAME_OPTIONS_HEADER = 'X-Frame-Options'.freeze
|
12
|
+
|
13
|
+
# @since 0.3.0
|
14
|
+
# @api private
|
15
|
+
#
|
16
|
+
# @see Lotus::Loader#_configure_controller_framework!
|
17
|
+
CONTENT_SECURITY_POLICY_HEADER = 'Content-Security-Policy'.freeze
|
18
|
+
|
19
|
+
# X-Frame-Options headers' value
|
20
|
+
#
|
21
|
+
# @overload x_frame_options(value)
|
22
|
+
# Sets the given value
|
23
|
+
# @param value [String] for X-Frame-Options header.
|
24
|
+
#
|
25
|
+
# @overload x_frame_options
|
26
|
+
# Gets the value
|
27
|
+
# @return [String] X-Frame-Options header's value
|
28
|
+
#
|
29
|
+
# @since 0.3.0
|
30
|
+
def x_frame_options(value = nil)
|
31
|
+
if value.nil?
|
32
|
+
@x_frame_options
|
33
|
+
else
|
34
|
+
@x_frame_options = value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Content-Policy-Security headers' value
|
39
|
+
#
|
40
|
+
# @overload content_security_policy(value)
|
41
|
+
# Sets the given value
|
42
|
+
# @param value [String] for Content-Security-Policy header.
|
43
|
+
#
|
44
|
+
# @overload content_security_policy
|
45
|
+
# Gets the value
|
46
|
+
# @return [String] Content-Security-Policy header's value
|
47
|
+
#
|
48
|
+
# @since 0.3.0
|
49
|
+
def content_security_policy(value = nil)
|
50
|
+
if value.nil?
|
51
|
+
@content_security_policy
|
52
|
+
else
|
53
|
+
@content_security_policy = value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|