Skip to content

Commit c198827

Browse files
committed
Initial Commit
0 parents  commit c198827

19 files changed

+536
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
/.bundle/
3+
/.yardoc
4+
/Gemfile.lock
5+
/_yardoc/
6+
/coverage/
7+
/doc/
8+
/pkg/
9+
/spec/reports/
10+
/tmp/

.rubocop.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
AllCops:
2+
TargetRubyVersion: 2.3
3+
DisplayCopNames: true
4+
ExtraDetails: true
5+
6+
Metrics/LineLength:
7+
Max: 140
8+
9+
Metrics/MethodLength:
10+
Max: 15
11+
12+
Style/Documentation:
13+
Enabled: false

CODE_OF_CONDUCT.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at [http://contributor-covenant.org/version/1/4][version]
72+
73+
[homepage]: http://contributor-covenant.org
74+
[version]: http://contributor-covenant.org/version/1/4/

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
# Specify your gem's dependencies in rails_console_commands.gemspec
6+
gemspec

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Tanda
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Rails Console Commands
2+
3+
An updated version of https://rubygems.org/gems/commands, which runs with Rails 5.x
4+
5+
## Installation
6+
7+
```ruby
8+
gem 'rails_console_commands'
9+
```
10+
11+
And then execute:
12+
13+
$ bundle
14+
15+
Or install it yourself as:
16+
17+
$ gem install rails_console_commands
18+
19+
## Usage
20+
21+
In your rails console, the following commands are now available:
22+
- `rake`
23+
- `test` (Only in a test console)
24+
- `generate`
25+
26+
### `rake`
27+
Use this to run rake tasks from your console. If you wanted to check the migration status of the database, you would run:
28+
```ruby
29+
rake 'db:migrate:status'
30+
```
31+
32+
### `test`
33+
Use this run your test suite, a single test file, or a single test from your console. If you wanted to run the test containing line 13 in
34+
`test/unit/user_test.rb`, you would run:
35+
```ruby
36+
test 'unit/user', 13
37+
```
38+
39+
**Note:** The line number argument is optional, but only available if you have the [M gem](https://rubygems.org/gems/m)
40+
41+
### `generate`
42+
Use this to run rails generators from your console. If you wanted to generate a migration, you would run:
43+
```ruby
44+
generate 'migration MyMigration'
45+
```
46+
47+
## Development
48+
49+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50+
51+
To install this gem onto your local machine, run `bundle exec rake install`. 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, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52+
53+
## Contributing
54+
55+
Bug reports and pull requests are welcome on GitHub at https://github.com/TandaHQ/rails_console_commands. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
56+
57+
## License
58+
59+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
60+
61+
## Code of Conduct
62+
63+
Everyone interacting in the RailsConsoleCommands project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rails_console_commands/blob/master/CODE_OF_CONDUCT.md).

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
require 'bundler/gem_tasks'
4+
require 'rubocop/rake_task'
5+
6+
RuboCop::RakeTask.new(:rubocop)
7+
8+
task default: :rubocop

bin/console

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'bundler/setup'
5+
require 'rails_console_commands'
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
# (If you use this, don't forget to add pry to your Gemfile!)
11+
# require "pry"
12+
# Pry.start
13+
14+
require 'irb'
15+
IRB.start(__FILE__)

bin/setup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

lib/rails_console_commands.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails/console/app'
4+
require_relative './rails_console_commands/console_delegation'
5+
require_relative './rails_console_commands/version'
6+
7+
Rails::ConsoleMethods.send :include, RailsConsoleCommands::ConsoleDelegation
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require_relative './raker'
4+
require_relative './tester'
5+
require_relative './generator'
6+
7+
module RailsConsoleCommands
8+
class Commander
9+
delegate :rake, to: :raker
10+
delegate :test, to: :tester
11+
delegate :generate, :destroy, :update, to: :generator
12+
13+
attr_reader :raker, :tester, :generator
14+
15+
def initialize
16+
@raker = Raker.new
17+
@tester = Tester.new
18+
@generator = Generator.new
19+
end
20+
end
21+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require_relative './commander'
4+
5+
module RailsConsoleCommands
6+
module ConsoleDelegation
7+
def commander
8+
@commander ||= Commander.new
9+
end
10+
11+
def test(*args)
12+
if Rails.env.test?
13+
commander.test(*args)
14+
else
15+
puts 'You can only run tests in a console started in the test environment. ' \
16+
'Use `rails console test` to start such a console'
17+
end
18+
end
19+
20+
delegate :rake, :generate, :destroy, :update, to: :commander
21+
end
22+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
module RailsConsoleCommands
4+
module Environment
5+
def self.fork
6+
Kernel.fork do
7+
yield
8+
Kernel.exit
9+
end
10+
11+
Process.waitall
12+
end
13+
end
14+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails/generators'
4+
5+
module RailsConsoleCommands
6+
class Generator
7+
def initialize
8+
load_rails_generators
9+
end
10+
11+
def generate(argv = nil)
12+
generator :generate, argv
13+
end
14+
15+
def update(argv = nil)
16+
generator :update, argv
17+
end
18+
19+
def destroy(argv = nil)
20+
generator :destroy, argv
21+
end
22+
23+
private
24+
25+
def load_rails_generators
26+
Rails.application.load_generators
27+
end
28+
29+
def generator(name, argv = nil)
30+
if argv.nil?
31+
# FIXME: I don't know why we can't just catch SystemExit here, then we wouldn't need this if block
32+
Rails::Generators.help name
33+
else
34+
argv = argv.split(' ') if argv.respond_to?(:split)
35+
argv ||= []
36+
Rails::Command.invoke('generate', argv)
37+
end
38+
39+
'Completed'
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)