foobara-rails-command-connector 0.1.2 → 0.1.3
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +63 -8
- data/lib/foobara/rails/routes.rb +11 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c82d23ac51a683a323ec7b818c23576bc09d4b5eba02702244e2b283da5d3071
|
|
4
|
+
data.tar.gz: d3ac1925680b0f9e91d27bfe5b1543ec6edf25b89f25321d5bce2dd6ed38d905
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14d78b832cbe1a1930a6141bfbfc02126077d647a5dc6f22bf33992ccc18bc8233919d76a45ce80aee7ebcd0bef0d63101ece48725187cdbfc409d9b9b482033
|
|
7
|
+
data.tar.gz: 041add2bddd85e3ef0821eb57de88c7e904904027b488d03b8a20b64ac1d15e67c5c292b308269f7e1269286c6bb1e2be7fe7b7d328a57d832020434b4d053f5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,24 +1,79 @@
|
|
|
1
1
|
# Foobara::RailsCommandConnector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A command connector for Foobara that exposes commands via a shell command-line interface (CLI). This connector parses command-line arguments and routes them to Foobara commands, making it easy to build CLI tools from your Foobara commands.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Add `gem "foobara-rails-command-connector"` to your Gemfile.
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### Option 1: Use the connector directly from a file in config/initializers
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
require "foobara/rails_command_connector"
|
|
15
|
+
|
|
16
|
+
connector = Foobara::CommandConnectors::RailsCommandConnector.new
|
|
17
|
+
|
|
18
|
+
connector.connect(CreateCapybara)
|
|
19
|
+
connector.connect(IncrementAge)
|
|
20
|
+
connector.connect(FindCapybara)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Option 2: Expose commands using `command` when drawing routes
|
|
24
|
+
|
|
25
|
+
This `command` method just calls `CommandConnector#connect` under the hood. It supports
|
|
26
|
+
the same DSL and all the same features. It just gives a way for commands exposed in this manner to
|
|
27
|
+
live with your non-Foobara routes.
|
|
28
|
+
|
|
29
|
+
A `RailsCommandConnector` will be automatically created if one doesn't exist, so you can simply:
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
require "foobara/rails/routes"
|
|
33
|
+
|
|
34
|
+
Rails.application.routes.draw do
|
|
35
|
+
command CreateCapybara
|
|
36
|
+
command IncrementAge
|
|
37
|
+
command FindCapybara
|
|
38
|
+
end
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If you need to customize the connector (e.g., set a prefix), you can create it manually before using `command`:
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
require "foobara/rails_command_connector"
|
|
45
|
+
Foobara::CommandConnectors::RailsCommandConnector.new(prefix: ["api"])
|
|
46
|
+
require "foobara/rails/routes"
|
|
47
|
+
|
|
48
|
+
Rails.application.routes.draw do
|
|
49
|
+
command CreateCapybara
|
|
50
|
+
command IncrementAge
|
|
51
|
+
command FindCapybara
|
|
52
|
+
end
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Once you have done one of these options, you can view your commands at `/help` and run
|
|
56
|
+
your commands from `/run`. You can then import your commands into other systems using
|
|
57
|
+
the `foobara-remote-imports` gem and pointing it at `/manifest`. You can generate a
|
|
58
|
+
Typescript SDK with `foob g foob g typescript-remote-commands --manifest-url http://localhost:3000/manifest`
|
|
59
|
+
or forms with
|
|
60
|
+
`foob g typescript-react-command-form --manifest-url http://localhost:3000/manifest --command CreateCommand`.
|
|
12
61
|
|
|
13
62
|
## Development
|
|
14
63
|
|
|
15
|
-
|
|
64
|
+
### Contributing
|
|
65
|
+
|
|
66
|
+
Filing bug reports or reporting any issues with using this or any foobara gem would be mighty helpful and appreciated!
|
|
67
|
+
|
|
68
|
+
If you would like to help contributing art/code/documentation/whatever please get in touch!
|
|
16
69
|
|
|
17
|
-
|
|
70
|
+
### Contributing code
|
|
18
71
|
|
|
19
|
-
|
|
20
|
-
|
|
72
|
+
You should be able to fork the repo, clone it locally, run `bundle` and then `rake` to run
|
|
73
|
+
the test suite and linter. Make your changes and push them up and open a PR!
|
|
74
|
+
If you need any help, please reach out and we're happy to help!
|
|
21
75
|
|
|
22
76
|
## Licensing
|
|
23
77
|
|
|
24
|
-
|
|
78
|
+
foobara-rails-command-connector is licensed under the Mozilla Public License Version 2.0.
|
|
79
|
+
Please see LICENSE.txt for more info.
|
data/lib/foobara/rails/routes.rb
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
ActionDispatch::Routing::Mapper.class_eval do
|
|
2
|
-
command_connector = Rails.application.config.foobara_command_connector
|
|
3
|
-
|
|
4
2
|
define_method :command do |*args, **opts, &block|
|
|
3
|
+
command_connector = Rails.application.config.foobara_command_connector
|
|
4
|
+
|
|
5
|
+
unless command_connector
|
|
6
|
+
require "foobara/rails_command_connector"
|
|
7
|
+
command_connector = Foobara::CommandConnectors::RailsCommandConnector.new
|
|
8
|
+
# Ensure the connector is attached to config even if install! was skipped
|
|
9
|
+
# (e.g., if installation was already done by a previous connector)
|
|
10
|
+
# We check again in case install! attached a different instance (shouldn't happen, but safe)
|
|
11
|
+
command_connector.attach_to_rails_application_config! if Rails.application.config.foobara_command_connector.nil?
|
|
12
|
+
end
|
|
13
|
+
|
|
5
14
|
command_connector.connect(*args, **opts, &block)
|
|
6
15
|
end
|
|
7
16
|
end
|