Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sungwoncho/pattern_generator
The missing Rails generator for patterns
https://github.com/sungwoncho/pattern_generator
cli generator rails
Last synced: 6 days ago
JSON representation
The missing Rails generator for patterns
- Host: GitHub
- URL: https://github.com/sungwoncho/pattern_generator
- Owner: sungwoncho
- License: mit
- Created: 2015-06-10T07:52:42.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-13T03:46:03.000Z (over 7 years ago)
- Last Synced: 2024-04-25T10:22:25.890Z (7 months ago)
- Topics: cli, generator, rails
- Language: Ruby
- Homepage:
- Size: 62.5 KB
- Stars: 16
- Watchers: 6
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: MIT-LICENSE
- Code of conduct: code_of_conduct.md
Awesome Lists containing this project
README
# Pattern Generator [![Build Status](https://travis-ci.org/sungwoncho/pattern_generator.svg?branch=master)](https://travis-ci.org/sungwoncho/pattern_generator)
Pattern Generator lets you generate various Rails patterns and tests with a single
command.## Install
In your Gemfile, add the gem in the development group.
```ruby
gem 'pattern_generator', group: :development
```Run `bundle install` to install the gem.
Now you are ready to rock the pattern generator!
## Usage
```
rails generate [PATTERN_TYPE] [YOUR_FILE_NAME (in snake_case)]
```Currently, PATTERN_TYPE can be:
* Service
* Policy
* PORO (Plain Old Ruby Object)
* FormDestroy command is also supported.
## Examples
Here are usage examples with commands and generated files.
### Service
```
rails generate service find_match
```generates:
*app/services/find_match_service.rb*
```ruby
class FindMatchService
def initializeend
end
```*spec/services/find_match_service_spec.rb*
```ruby
require 'rails_helper'RSpec.describe FindMatchService, type: :service do
describe '#call' do
pending "Add some tests to #{__FILE__}"
end
end
```### Policy
```
rails generate policy voting
```generates:
*app/policies/voting_policy.rb*
```ruby
class VotingPolicy
def initializeend
end
```*spec/policies/voting_policy_spec.rb*
```ruby
require 'rails_helper'RSpec.describe VotingPolicy, type: :policy do
describe '#policy_method' do
pending "Add some tests to #{__FILE__}"
end
end
```### PORO (Plain Old Ruby Object)
a minimalistic non-ActiveRecord model that can be customized to fit your needs
```
rails generate poro payment_gateway
```generates:
*app/models/payment_gateway.rb*
```ruby
class PaymentGateway
def initializeend
end```
*spec/policies/payment_gateway_spec.rb*
```ruby
require 'rails_helper'RSpec.describe PaymentGateway do
describe 'something' do
pending "Add some tests to #{__FILE__}"
end
end```
## Options
* `--minitest`
* Will create your test files inside test folder.
* DEFAULT: `--rspec`
* Will create your test files inside spec folder.* Usage: `rails generate service subscribe_user --minitest`
## Where can I learn about more patterns?
* [7 Patterns to Refactor Fat ActiveRecord Models](http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/)
Feel free to add good blog articles or tutorials here.
## Contributing
Know your patterns? Open a pull request!
This project respects the [contributor code of conduct](https://github.com/sungwoncho/pattern_generator/blob/master/code_of_conduct.md).
## License
This project rocks and uses MIT-LICENSE.