Skip to content

Commit

Permalink
feat: add Rake task (#41)
Browse files Browse the repository at this point in the history
# Issue

Closes #40.

# Overview

As the title states, this PR adds a Rake task for Chusaku. This allows
users to use a Rake task to execute Chusaku in addition to the
executable it ships with like such:

```sh
bin/rake chusaku -- --dry-run
```

Loading the gem's Rake tasks is a matter of adding a one-liner to a
project's `Rakefile`:

```ruby
Chusaku.load_tasks
```

Users will need to update their `Gemfile` such that Chusaku isn't being
required with the `require: false` flag:

```ruby
# BAD
gem "chusaku", require: false

# GOOD
gem "chusaku"
```

---------

Co-authored-by: Gareth Jones <[email protected]>
  • Loading branch information
nshki and G-Rath authored Jan 5, 2024
1 parent 7bc0f94 commit c35763b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ["2.6", "2.7", "3.0"]
ruby-version: ["2.7", "3.0", "3.1", "3.2", "3.3"]
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
/spec/reports/
/tmp/

.ruby-version
Gemfile.lock
43 changes: 28 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,23 @@ Add this line to your Rails application's Gemfile:

```ruby
group :development do
# ...
gem "chusaku", require: false
# ...
end
```

And then execute:

```
$ bundle install
```sh
bundle install
```


## Usage

From the root of your Rails application, run:

```
$ bundle exec chusaku
```sh
bundle exec chusaku
```

Chusaku has some flags available for use as well:
Expand All @@ -61,17 +59,32 @@ Usage: chusaku [options]
```

### Rake usage

If you'd like to use Chusaku as a Rake task, add the following line to your `Rakefile`:

```ruby
require "chusaku"
Chusaku.load_tasks
```

This will then allow you to call:

```sh
bin/rake chusaku
```

To pass flags, pass them like you would from the CLI executable:

```sh
bin/rake chusaku -- --dry-run --exit-with-error-on-annotation
```


## Development

Read the blog post explaining how the gem works at a high level:
https://nshki.com/chusaku-a-controller-annotation-gem.
Read the blog post explaining how the gem works at a high level: https://nshki.com/chusaku-a-controller-annotation-gem.

After checking out the repo, run `bin/setup` to install dependencies. Then, run
`bundle exec rake test` to run the tests. You can also run `bin/console` for an
interactive prompt that will allow you to experiment.
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To release a new version, update the version number in `version.rb`, and then
run `bundle exec rake release`, which will create a git tag for the version,
git commits and tags, and push the `.gem` file to
[rubygems.org](https://rubygems.org).
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
9 changes: 9 additions & 0 deletions lib/chusaku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ def call(flags = {})
output_results
end

# Load Rake tasks for Chusaku. Should be called in your project's `Rakefile`.
#
# @return [void]
def load_tasks
Dir[File.join(File.dirname(__FILE__), "tasks", "**/*.rake")].each do |task|
load(task)
end
end

private

# Adds annotations to the given file.
Expand Down
8 changes: 8 additions & 0 deletions lib/tasks/chusaku.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
chusaku_lib = File.expand_path(File.dirname(__FILE__, 2))

desc "Add route annotations to your Rails actions"
task chusaku: :environment do
require "#{chusaku_lib}/chusaku/cli"

Chusaku::CLI.new.call(ARGV[2...] || [])
end

0 comments on commit c35763b

Please sign in to comment.