rails_console_commands 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84e53e385f41975aaf3b56f6f586da95a1d82064
4
+ data.tar.gz: f30251daa6abbc000a9b75a9359414e6f71dda6a
5
+ SHA512:
6
+ metadata.gz: 6cc28120991548f18efa034fd32ee88d74ea834dc95804212348a790048bcfde08476802ebd9611a2f0397dd177b03ffda9ad47a665db1d8a56ddf35d54c8ecb
7
+ data.tar.gz: 15ec65ee6405e489ae042f880ddd32b675a024c1520e038b7ddaf581f384878d354590d27240905d99f942592d1bc0f1f99d393fd7845faeaf13ef85ae324448
@@ -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 dave@tanda.co. 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/
data/Gemfile ADDED
@@ -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
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -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).
@@ -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
@@ -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
@@ -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
@@ -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,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake'
4
+
5
+ module RailsConsoleCommands
6
+ class Raker
7
+ include Rake::DSL
8
+
9
+ def initialize
10
+ load_rake_tasks
11
+ end
12
+
13
+ def rake(task = nil)
14
+ task.nil? ? print_rake_tasks : invoke_rake_task(task)
15
+ 'Completed'
16
+ rescue SystemExit, RuntimeError => e
17
+ "Failed: #{e.message}"
18
+ end
19
+
20
+ private
21
+
22
+ def load_rake_tasks
23
+ Rake::TaskManager.record_task_metadata = true # needed to capture comments from define_task
24
+ load Rails.root.join('Rakefile')
25
+ end
26
+
27
+ def print_rake_tasks
28
+ Rake.application.options.show_tasks = :tasks
29
+ Rake.application.options.show_task_pattern = Regexp.new('')
30
+ Rake.application.display_tasks_and_comments
31
+ end
32
+
33
+ def invoke_rake_task(task)
34
+ task, *options = task.split(' ')
35
+
36
+ ARGV.replace options
37
+
38
+ # FIXME: Before we can use this, we need a way to reset the options again
39
+ # Rake.application.handle_options
40
+
41
+ expose_argv_arguments_via_env { Rake::Task[task].invoke }
42
+ Rake.application.tasks.each(&:reenable) # Rake by default only allows tasks to be run once per session
43
+ ensure
44
+ ARGV.replace([])
45
+ end
46
+
47
+ def expose_argv_arguments_via_env
48
+ argv_arguments.each { |key, value| ENV[key] = value }
49
+ yield
50
+ ensure
51
+ argv_arguments.keys.each { |key| ENV.delete(key) }
52
+ end
53
+
54
+ def argv_arguments
55
+ ARGV.each_with_object({}) do |arg, arguments|
56
+ if arg =~ /^(\w+)=(.*)$/
57
+ arguments[Regexp.last_match(1)] = Regexp.last_match(2)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './environment'
4
+
5
+ module RailsConsoleCommands
6
+ module TestEnvironment
7
+ class << self
8
+ def fork
9
+ Environment.fork do
10
+ setup_for_test
11
+ yield
12
+ end
13
+
14
+ reset_active_record
15
+ end
16
+
17
+ private
18
+
19
+ def setup_for_test
20
+ reload_classes
21
+ add_test_dir_to_load_path
22
+ end
23
+
24
+ def reload_classes
25
+ # Overwrite the default config.cache_classes = true,
26
+ # so we can change classes in the test session.
27
+ ActiveSupport::Dependencies.mechanism = :load
28
+
29
+ Rails.application.reloader.reload!
30
+ Rails.application.reloader.prepare!
31
+ end
32
+
33
+ def reset_active_record
34
+ return unless defined? ApplicationRecord
35
+ ApplicationRecord.clear_active_connections!
36
+ ApplicationRecord.establish_connection
37
+ end
38
+
39
+ def add_test_dir_to_load_path
40
+ test_path = Rails.root.join('test')
41
+ $LOAD_PATH.unshift(test_path) unless $LOAD_PATH.first == test_path
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './test_environment'
4
+
5
+ module RailsConsoleCommands
6
+ class Tester
7
+ def test(what = nil, line = nil)
8
+ case what
9
+ when NilClass
10
+ print_test_usage
11
+ when 'all'
12
+ run('test/**/**/*_test.rb', line)
13
+ when %r{^[^/]+$} # models
14
+ run("test/#{what}/**/*_test.rb", line)
15
+ when %r{[/]+} # models/person
16
+ run("test/#{what}_test.rb", line)
17
+ end
18
+
19
+ 'Completed'
20
+ end
21
+
22
+ private
23
+
24
+ def run(test_pattern, line = nil)
25
+ line = nil unless line_available?(test_pattern, line)
26
+
27
+ TestEnvironment.fork do
28
+ if line
29
+ Minitest.class_variable_set(:@@installed_at_exit, true)
30
+ M::Runner.new(["#{test_pattern}:#{line}"]).run
31
+ else
32
+ Dir[test_pattern].each do |path|
33
+ require File.expand_path(path)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def print_test_usage
40
+ puts <<-EOT
41
+ Usage:
42
+ test "WHAT"[, line_number]
43
+
44
+ Description:
45
+ Runs either a full set of test suites or single suite.
46
+
47
+ If you supply WHAT with either models, controllers, helpers, integration, or performance,
48
+ those whole sets will be run.
49
+
50
+ If you supply WHAT with models/person, just test/models/person_test.rb will be run.
51
+ EOT
52
+ end
53
+
54
+ def line_available?(test_pattern, line)
55
+ return false unless line
56
+
57
+ unless defined?(M::Runner)
58
+ puts "WARNING: You attempted to define a line number, but you don't have the 'm' gem. " \
59
+ "Please install the 'm' gem if you which to define line numbers"
60
+ return false
61
+ end
62
+
63
+ if test_pattern.include?('*')
64
+ puts 'WARNING: Using wildcard runner, line number ignored.'
65
+ return false
66
+ end
67
+
68
+ true
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsConsoleCommands
4
+ VERSION = '0.1.0'
5
+ end
@@ -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
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_console_commands
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Allie
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.49'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.49'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5'
69
+ description:
70
+ email:
71
+ - dave@tanda.co
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - CODE_OF_CONDUCT.md
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - lib/rails_console_commands.rb
81
+ - lib/rails_console_commands/commander.rb
82
+ - lib/rails_console_commands/console_delegation.rb
83
+ - lib/rails_console_commands/environment.rb
84
+ - lib/rails_console_commands/generator.rb
85
+ - lib/rails_console_commands/raker.rb
86
+ - lib/rails_console_commands/test_environment.rb
87
+ - lib/rails_console_commands/tester.rb
88
+ - lib/rails_console_commands/version.rb
89
+ homepage: https://github.com/TandaHQ/rails_console_commands
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.8
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Run rake/rails and test commands through the console
113
+ test_files: []