-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update cable_ready channel generator #1
update cable_ready channel generator #1
Conversation
The most important changes: add class options add tests add default values for prompts change generator name from `cable_ready_channel` to `cable_ready:channel`
private | ||
|
||
def using_broadcast_to? | ||
@using_broadcast_to ||= options.fetch(:broadcast_to) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we explain the use of options
in the USAGE
file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options get generated by rails itself. Unless you mean to explicitly add some examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it I run —help, it will show me those options? Sorry, haven’t had the time to check it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
❯ rails g cable_ready:channel 15:42:34
Usage:
rails generate cable_ready:channel NAME [options]
Options:
[--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated applications)
[--stimulus], [--no-stimulus] # Indicates when to generate stimulus
[--broadcast-to], [--no-broadcast-to] # Indicates when to generate broadcast to
[--resource=RESOURCE] # Indicates when to generate resource
[--identifier=IDENTIFIER] # Indicates when to generate identifier
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend], [--no-pretend] # Run but do not make any changes
-q, [--quiet], [--no-quiet] # Suppress status output
-s, [--skip], [--no-skip] # Skip files that already exist
Description:
Create an ActionCable channel ready for usage with CableReady
Example:
bin/rails generate cable_ready:channel Thing
This will create:
app/channels/thing_channel.rb
app/javascript/channels/thing_channel.js
app/javascript/controllers/thing_controller.js (Optional)
# some tests without generator options to simulate the inputs passed via cli | ||
|
||
test "should generate channel with the same resource name and stimulus controller (without options)" do | ||
CableReady::ChannelGenerator.any_instance.stubs(:using_broadcast_to?).returns(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with the use of mocha
, let's see what the others say 🙉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, just learnd about it today. I'm happy to remove all mocha tests since they are basically a copy from the ones above to tests it without the options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s a decent lib!
@julianrubisch I just had another idea to make the whole thing even easier and with less options. How do you feel about this: rails g cable_ready:channel --stream-for=Post --stimulus
# instead of
rails g cable_ready:channel --broadcast-to --resource=Post --stimulus and rails g cable_ready:channel --stream-from=post
# instead of
rails g cable_ready:channel --no-broadcast-to --identifier=post |
Good idea as long as it works without any options still 😉 |
That's the idea and I don't see why it shouldn't. I will refactor the PR! |
As discussed on Discord, here the PR with my recommended changes:
The most important changes:
cable_ready_channel
tocable_ready:channel