Skip to content
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

Merged

Conversation

marcoroth
Copy link

As discussed on Discord, here the PR with my recommended changes:

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

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) {
Copy link
Owner

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?

Copy link
Author

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?

Copy link
Owner

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

Copy link
Author

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)
Copy link
Owner

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 🙉

Copy link
Author

@marcoroth marcoroth Feb 1, 2021

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

Copy link
Owner

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!

@marcoroth
Copy link
Author

marcoroth commented Feb 1, 2021

@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

@julianrubisch
Copy link
Owner

Good idea as long as it works without any options still 😉

@marcoroth
Copy link
Author

That's the idea and I don't see why it shouldn't. I will refactor the PR!

@julianrubisch julianrubisch merged commit d927242 into julianrubisch:channel-generator Feb 1, 2021
@marcoroth marcoroth deleted the channel-generator branch February 1, 2021 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants