safeconsole 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a5f4f01969fa2f90339f8243412396ff39990da4ee8b7b4c5c9affc3e8199635
4
+ data.tar.gz: 9ca18ca05a24cf400a3baaf6a0a74b0f7c5ab7ee856a2734ffcde570736a3e08
5
+ SHA512:
6
+ metadata.gz: 16821e6d7ba50c2c1c7b98f20b706ffe2f53cb8704e23153281fe0fdbf411e2178bcfb9cbcbd51129d86bdb64c626a7406d64720ff543a54f2d60f8adcdb13c6
7
+ data.tar.gz: f4c1df276e2b78947d30ddf5dd0fe84f65e010058c38bd1ebaddc943b26a589a9cb436017ef6a0361418cf1632b9deeb6e894b9bc1d33fe01d4e653bd0915566
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,2 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-02-26
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at aaron@aaronmiler.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in safeconsole.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "standard", "~> 1.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ safeconsole (1.0.0)
5
+ artii
6
+ pry
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ artii (2.1.2)
12
+ ast (2.4.2)
13
+ coderay (1.1.3)
14
+ diff-lcs (1.5.0)
15
+ json (2.6.3)
16
+ language_server-protocol (3.17.0.3)
17
+ method_source (1.0.0)
18
+ parallel (1.22.1)
19
+ parser (3.2.1.0)
20
+ ast (~> 2.4.1)
21
+ pry (0.14.2)
22
+ coderay (~> 1.1)
23
+ method_source (~> 1.0)
24
+ rainbow (3.1.1)
25
+ rake (13.0.6)
26
+ regexp_parser (2.7.0)
27
+ rexml (3.2.5)
28
+ rspec (3.12.0)
29
+ rspec-core (~> 3.12.0)
30
+ rspec-expectations (~> 3.12.0)
31
+ rspec-mocks (~> 3.12.0)
32
+ rspec-core (3.12.1)
33
+ rspec-support (~> 3.12.0)
34
+ rspec-expectations (3.12.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.12.0)
37
+ rspec-mocks (3.12.3)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.12.0)
40
+ rspec-support (3.12.0)
41
+ rubocop (1.44.1)
42
+ json (~> 2.3)
43
+ parallel (~> 1.10)
44
+ parser (>= 3.2.0.0)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8, < 3.0)
47
+ rexml (>= 3.2.5, < 4.0)
48
+ rubocop-ast (>= 1.24.1, < 2.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 2.4.0, < 3.0)
51
+ rubocop-ast (1.26.0)
52
+ parser (>= 3.2.1.0)
53
+ rubocop-performance (1.15.2)
54
+ rubocop (>= 1.7.0, < 2.0)
55
+ rubocop-ast (>= 0.4.0)
56
+ ruby-progressbar (1.11.0)
57
+ standard (1.24.3)
58
+ language_server-protocol (~> 3.17.0.2)
59
+ rubocop (= 1.44.1)
60
+ rubocop-performance (= 1.15.2)
61
+ unicode-display_width (2.4.2)
62
+
63
+ PLATFORMS
64
+ arm64-darwin-21
65
+
66
+ DEPENDENCIES
67
+ rake (~> 13.0)
68
+ rspec (~> 3.0)
69
+ safeconsole!
70
+ standard (~> 1.3)
71
+
72
+ BUNDLED WITH
73
+ 2.3.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Aaron Miler
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,90 @@
1
+ # Safeconsole
2
+
3
+ Safeconsole is a utility for a safe by default `rails console`. Every session is wrapped in an
4
+ Active Record transaction, preventing accidental mutations on production data.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'safeconsole'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ ## Usage
19
+
20
+ Start Safeconsole session by running `bin/rails safeconsole`
21
+
22
+ ### Commands
23
+
24
+ The following commands are available in the Safeconsole session
25
+
26
+ - `commit`: Set the changes in the transaction to be committed to the database
27
+ - `nevermind`: Set the changes in the transaction to be discarded
28
+ - `refresh`: Start a new transaction, and discard or commit changes based on configuration
29
+ - `stats`: Display some stats on the current Safeconsole session
30
+ - `commands`: Print the Safeconsole commands in your session
31
+
32
+ ## Configuration
33
+
34
+ Safeconsole is configurable. You can configure it by adding an initializer at `config/initializers/safeconsole.rb` with the options outlined below
35
+
36
+ Example config, and options
37
+ ```ruby
38
+ # config/initializers/safeconsole.rb
39
+
40
+ Safeconsole.configure do |conf|
41
+ # App Name
42
+ # Name of the rails app, only for display purposes in the welcome message
43
+ # Default: Attempt to infer application name
44
+ conf.app_name = "My Amazing Product"
45
+
46
+ # Allow Unsafe
47
+ # Should safe console allow unsafe consoles in the listed environments
48
+ # Default: false
49
+ conf.allow_unsafe = true
50
+
51
+ # Current Environment
52
+ # What is the current runtime environment?
53
+ # Useful if Rails.env is `production` in staging like environments
54
+ # Default: Rails.env
55
+ conf.current_env = ENV["CURRENT_ENVIRONEMNT"]
56
+
57
+ # Command Timeout
58
+ # Should someone be removed from a console session with X duration of inactivity
59
+ # Default: nil
60
+ conf.command_timeout = 10.minutes
61
+
62
+ # Session Timeout
63
+ # What's the maximum duration someone should be allowed to run a console session?
64
+ # Default: nil
65
+ conf.session_timeout = 30.minutes
66
+ end
67
+ ```
68
+
69
+ ### Regarding Command and Session Timeouts
70
+
71
+ Both timeout configurations can be used together, independently, or not at all. Safeconsole spins up a
72
+ background thread to monitor current session duration, to prevent hanging console sessions.
73
+
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ There is a slimmed down Rails application in `spec/rails_app`, where you can run `bin/rails safeconsole` to see it in a rails app
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aaronmiler/safeconsole. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/aaronmiler/safeconsole/blob/main/CODE_OF_CONDUCT.md).
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
87
+
88
+ ## Code of Conduct
89
+
90
+ Everyone interacting in the Safeconsole project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/aaronmiler/safeconsole/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -0,0 +1,29 @@
1
+ module Safeconsole
2
+ module Commands
3
+ def commands
4
+ print_message(:commands)
5
+ end
6
+
7
+ def refresh
8
+ "safeconsole#refresh"
9
+ end
10
+
11
+ def done
12
+ Console.done!
13
+ end
14
+
15
+ def commit
16
+ Console.__console_commit = true
17
+ print_message(:commit)
18
+ end
19
+
20
+ def nevermind
21
+ Console.__console_commit = false
22
+ print_message(:nevermind)
23
+ end
24
+
25
+ def stats
26
+ print_message(:session_stats)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ module Safeconsole
2
+ class Configuration
3
+ attr_accessor :app_name,
4
+ :allow_unsafe,
5
+ :current_env,
6
+ :environments,
7
+ :command_timeout,
8
+ :session_timeout
9
+
10
+ def initialize
11
+ @environments = %w[]
12
+ @app_name = Utils.get_app_name
13
+ @allow_unsafe = true
14
+ @current_env = Rails.env
15
+ end
16
+ end
17
+
18
+ class << self
19
+ def allow_unsafe?
20
+ config.allow_unsafe
21
+ end
22
+
23
+ def watch_session?
24
+ config.command_timeout.present? || config.session_timeout.present?
25
+ end
26
+
27
+ def env
28
+ config.current_env
29
+ end
30
+
31
+ def config
32
+ @configuration ||= Configuration.new
33
+ end
34
+
35
+ def configure
36
+ yield config
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ require "pry"
2
+ require "singleton"
3
+
4
+ module Safeconsole
5
+ class Console
6
+ include Singleton
7
+ include Messages
8
+
9
+ extend Commands
10
+
11
+ class << self
12
+ attr_accessor :__console_done, :__console_commit
13
+
14
+ def run
15
+ print_message(:welcome)
16
+ print_message(:commands)
17
+
18
+ SessionWatcher.watch_session! if Safeconsole.watch_session?
19
+
20
+ print_message(:session_start)
21
+
22
+ loop do
23
+ @__console_done = false
24
+ @__console_commit = false
25
+ print_message(:transaction_start)
26
+
27
+ ActiveRecord::Base.transaction do
28
+ binding.pry quiet: true, prompt_name: "safeconsole" # standard:disable Lint/Debugger
29
+
30
+ raise ActiveRecord::Rollback unless @__console_commit
31
+ end
32
+
33
+ break print_message(:done) if @__console_done
34
+
35
+ print_message(:refresh)
36
+ sleep 0.5
37
+ end
38
+ end
39
+
40
+ def done!
41
+ @__console_done = true
42
+ @__exit_safeconsole = true
43
+ end
44
+
45
+ def done?
46
+ @__console_done
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,122 @@
1
+ require "artii"
2
+
3
+ module Safeconsole
4
+ module Messages
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def print_message(message_name)
11
+ puts Messages.send(message_name)
12
+ end
13
+ end
14
+
15
+ def self.respond_to_missing?(_name, _include_private)
16
+ true
17
+ end
18
+
19
+ def self.method_missing(method)
20
+ "**** Unknown Message #{method} ****"
21
+ end
22
+
23
+ module_function
24
+
25
+ def app_name
26
+ a = Artii::Base.new font: "slant"
27
+ a.asciify(Safeconsole.config.app_name)
28
+ end
29
+
30
+ def welcome
31
+ <<~MSG
32
+ #{app_name}
33
+
34
+ Current Rails Env: #{Safeconsole.config.current_env}
35
+
36
+ Welcome to safeconsole, you're in good hands.
37
+
38
+ MSG
39
+ end
40
+
41
+ def commands
42
+ <<~MSG
43
+ Usage:
44
+ - refresh: Load a new transaction (and commit if configured)
45
+ - commit: Set this transaction to be commited to the DB on refresh/exit
46
+ - nevermind: Set this transaction to be *discarded* on refresh/exit
47
+ - stats: Print the current transaction and session stats (commit status, length, stats)
48
+ - commands: Print command instructions again
49
+
50
+ Hotkeys:
51
+ - ctrl+d: Load a new transaction (equivilent to refresh)
52
+
53
+ MSG
54
+ end
55
+
56
+ def session_stats
57
+ session_length = (Time.now - SessionWatcher.initialized_at).round
58
+ minutes, seconds = session_length.divmod(50)
59
+
60
+ <<~MSG
61
+ Session:
62
+ Length: #{minutes} minutes #{seconds} seconds
63
+ Commands: #{SessionWatcher.total_commands}
64
+
65
+ Transaction:
66
+ Commit: #{Console.__console_commit}
67
+ Commands: #{SessionWatcher.transaction_commands}
68
+ MSG
69
+ end
70
+
71
+ def commit
72
+ <<~MSG
73
+ This transaction will now be commited to the database on refresh/exit
74
+
75
+ If this was a mistake, run the command: nevermind
76
+ MSG
77
+ end
78
+
79
+ def nevermind
80
+ "Transaction changes will be discarded on refresh/exit"
81
+ end
82
+
83
+ def session_start
84
+ "You're a wizard, searching for a long lost artifact."
85
+ end
86
+
87
+ def transaction_start
88
+ "You begin casting a locating spell"
89
+ end
90
+
91
+ def refresh
92
+ "Your magic is running low. You stop casting to drink a potion, restoring your energy."
93
+ end
94
+
95
+ def done
96
+ "You've located the lost artifact!"
97
+ end
98
+
99
+ def session_expired
100
+ "You've been searching for too long. The artifact is lost forever."
101
+ end
102
+
103
+ def invalid_query
104
+ <<~MSG
105
+
106
+ Active Record Error!
107
+ Oops! Looks like you executed an invalid SQL query. This breaks the current transaction.
108
+
109
+ All ActiveRecord based interactions will be broken now. Grab a new transaction with the command: refresh
110
+
111
+ MSG
112
+ end
113
+
114
+ def unsafe_env
115
+ <<~MSG
116
+ SAFECONSOLE WARNING
117
+ Safeconsole is configured to not allow unsafe consoles for the current environment: #{Safeconsole.env}
118
+ This session will now exit. If this is a mistake, check your safeconsole configuration
119
+ MSG
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,26 @@
1
+ require "pry"
2
+
3
+ module Safeconsole
4
+ class PryConfig
5
+ def self.add_hooks
6
+ Pry.hooks.add_hook(:after_read, "safeconsole__transaction_watcher") do |output, binding, pry|
7
+ if defined?(ActiveRecord) && binding.last_exception.is_a?(ActiveRecord::StatementInvalid)
8
+ puts Messages.invalid_query
9
+ end
10
+ end
11
+
12
+ Pry.hooks.add_hook(:after_eval, "safeconsole__exit") do |output, binding, _pry|
13
+ if Object.const_defined?(:Safeconsole) && (binding.config.prompt_name == "safeconsole")
14
+ SessionWatcher.command_ran
15
+
16
+ binding.eval("exit") if Console.done?
17
+
18
+ if output == "safeconsole#refresh"
19
+ SessionWatcher.transaction_commands = 0
20
+ binding.eval("exit")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ require "safeconsole"
2
+ require "rails"
3
+
4
+ module Safeconsole
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ desc "start a Safeconsole session"
8
+ task safeconsole: :environment do
9
+ Safeconsole.start!
10
+ end
11
+ end
12
+
13
+ console do
14
+ if !Safeconsole.allow_unsafe? && Safeconsole.config.environments.include?(Rails.env)
15
+ puts Messages.unsafe_env
16
+ exit
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,49 @@
1
+ require "singleton"
2
+
3
+ module Safeconsole
4
+ class SessionWatcher
5
+ include Singleton
6
+ include Messages
7
+
8
+ @initialized_at = Time.now
9
+ @last_command_at = Time.now
10
+ @total_commands = 0
11
+ @transaction_commands = 0
12
+
13
+ class << self
14
+ attr_accessor :initialized_at, :last_command_at, :total_commands, :transaction_commands
15
+
16
+ def command_ran
17
+ @total_commands += 1
18
+ @transaction_commands += 1
19
+ @last_command_at = Time.now
20
+ end
21
+
22
+ def watch_session!
23
+ Thread.start do
24
+ loop do
25
+ if timeout_reached? || session_limit_reached?
26
+ print_message(:session_expired)
27
+ Console.__console_commit = false
28
+ break binding.eval("exit")
29
+ end
30
+
31
+ sleep 2
32
+ end
33
+ end
34
+ end
35
+
36
+ def session_limit_reached?
37
+ return false unless Safeconsole.config.session_timeout
38
+
39
+ @initialized_at < Safeconsole.config.session_timeout.ago
40
+ end
41
+
42
+ def timeout_reached?
43
+ return false unless Safeconsole.config.command_timeout
44
+
45
+ last_command_at < Safeconsole.config.command_timeout.ago
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ module Safeconsole
2
+ module Utils
3
+ module_function
4
+
5
+ def get_app_name
6
+ return Dir.pwd.split("/")[-1] unless defined?(Rails)
7
+ return Rails.application.class.parent_name if Rails.version <= "6.0"
8
+
9
+ Rails.application.class.module_parent_name
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Safeconsole
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "safeconsole/version"
4
+
5
+ require "safeconsole/utils"
6
+ require "safeconsole/configuration"
7
+ require "safeconsole/messages"
8
+ require "safeconsole/pry_config"
9
+ require "safeconsole/session_watcher"
10
+ require "safeconsole/commands"
11
+ require "safeconsole/console"
12
+
13
+ module Safeconsole
14
+ require "safeconsole/railtie" if defined?(Rails)
15
+
16
+ module_function
17
+
18
+ def start!
19
+ Safeconsole::PryConfig.add_hooks
20
+ Safeconsole::Console.run
21
+ end
22
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/safeconsole/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "safeconsole"
7
+ spec.version = Safeconsole::VERSION
8
+ spec.authors = ["Aaron Miler"]
9
+ spec.email = ["aaron@miler.to"]
10
+
11
+ spec.summary = "A safer version of rails console with Pry and Transactions"
12
+ spec.description = <<~DESC
13
+ A pry console that's safe for production use. Safeconsole wraps your console usage in
14
+ a transaction, allowing you to be sure of the actions you're taking, and preventing
15
+ accidental modifications to production data.
16
+ DESC
17
+ spec.homepage = "https://github.com/aaromiler/safeconsole"
18
+ spec.license = "MIT"
19
+ spec.required_ruby_version = ">= 2.6.0"
20
+
21
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
+
23
+ spec.metadata["homepage_uri"] = spec.homepage
24
+ spec.metadata["source_code_uri"] = "https://github.com/aaronmiler/safeconsole"
25
+ spec.metadata["changelog_uri"] = "https://github.com/aaronmiler/safeconsole/blob/main/CHANGELOG.md"
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject do |f|
31
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
32
+ end
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ # Uncomment to register a new dependency of your gem
39
+ spec.add_dependency "pry"
40
+ spec.add_dependency "artii"
41
+
42
+ # For more information and examples about making a new gem, check out our
43
+ # guide at: https://bundler.io/guides/creating_gem.html
44
+ end
@@ -0,0 +1,4 @@
1
+ module Safeconsole
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: safeconsole
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Miler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: artii
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: |
42
+ A pry console that's safe for production use. Safeconsole wraps your console usage in
43
+ a transaction, allowing you to be sure of the actions you're taking, and preventing
44
+ accidental modifications to production data.
45
+ email:
46
+ - aaron@miler.to
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".rspec"
52
+ - ".standard.yml"
53
+ - CHANGELOG.md
54
+ - CODE_OF_CONDUCT.md
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - lib/safeconsole.rb
61
+ - lib/safeconsole/commands.rb
62
+ - lib/safeconsole/configuration.rb
63
+ - lib/safeconsole/console.rb
64
+ - lib/safeconsole/messages.rb
65
+ - lib/safeconsole/pry_config.rb
66
+ - lib/safeconsole/railtie.rb
67
+ - lib/safeconsole/session_watcher.rb
68
+ - lib/safeconsole/utils.rb
69
+ - lib/safeconsole/version.rb
70
+ - safeconsole.gemspec
71
+ - sig/safeconsole.rbs
72
+ homepage: https://github.com/aaromiler/safeconsole
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ allowed_push_host: https://rubygems.org
77
+ homepage_uri: https://github.com/aaromiler/safeconsole
78
+ source_code_uri: https://github.com/aaronmiler/safeconsole
79
+ changelog_uri: https://github.com/aaronmiler/safeconsole/blob/main/CHANGELOG.md
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.6.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.2.22
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A safer version of rails console with Pry and Transactions
99
+ test_files: []