archer-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +107 -0
- data/lib/archer-rails.rb +1 -0
- data/lib/archer.rb +62 -0
- data/lib/archer/engine.rb +12 -0
- data/lib/archer/history.rb +5 -0
- data/lib/archer/version.rb +3 -0
- data/lib/generators/archer/install_generator.rb +38 -0
- data/lib/generators/archer/templates/migration.rb.tt +11 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bc91028877ce1f88f0b7a00d7ae59f560f54b810920b4b63182da896c9e3f763
|
4
|
+
data.tar.gz: adc85d772d7c4b8b8e603eb38d4980f7c1949cec7bbd610f21ade433f7f0a3cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 865302453215cfbb7401227d7d00ef7ecd0afaee60b2d113e5bb0e2c713a5158938edbf91fd1569d40e943a75dbe9a91eb3f709cba8d57820dcc2dff0c72dcd3
|
7
|
+
data.tar.gz: 8029f6e80439966df685d4402f72d40366e1f97bdfe2ae4ea1580cbce6c69625bd47df7b90248c6db9d336772b58514fd6083285d27663577de3cb45235943f9
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Andrew Kane
|
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,107 @@
|
|
1
|
+
# Archer
|
2
|
+
|
3
|
+
Rails console history for Heroku, Docker, and more
|
4
|
+
|
5
|
+
![Screenshot](https://ankane.org/images/archer-readme.png)
|
6
|
+
|
7
|
+
Designed for platforms with ephemeral filesystems
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application’s Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'archer-rails'
|
15
|
+
```
|
16
|
+
|
17
|
+
And run:
|
18
|
+
|
19
|
+
```sh
|
20
|
+
rails generate archer:install
|
21
|
+
rails db:migrate
|
22
|
+
```
|
23
|
+
|
24
|
+
Lastly, update your Gemfile to only include it in environments where you need it:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'archer-rails', group: [:production]
|
28
|
+
```
|
29
|
+
|
30
|
+
## How It Works
|
31
|
+
|
32
|
+
Ruby stores console history in a file specified by:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
IRB.conf[:HISTORY_FILE]
|
36
|
+
```
|
37
|
+
|
38
|
+
This file gets lost on ephemeral filesystems. Instead, we store its contents in the database.
|
39
|
+
|
40
|
+
## Users
|
41
|
+
|
42
|
+
Each user can keep their own history. The user determined by `ENV["USER"]` by default. You can specify a user when starting the console with:
|
43
|
+
|
44
|
+
```sh
|
45
|
+
USER=andrew rails console
|
46
|
+
```
|
47
|
+
|
48
|
+
Confirm it worked with:
|
49
|
+
|
50
|
+
```rb
|
51
|
+
Archer.user
|
52
|
+
```
|
53
|
+
|
54
|
+
## Clearing History
|
55
|
+
|
56
|
+
Clear history for current user with:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
Archer.clear
|
60
|
+
```
|
61
|
+
|
62
|
+
## Configuration
|
63
|
+
|
64
|
+
Change the number of commands to remember
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
Archer.limit = 200 # default
|
68
|
+
```
|
69
|
+
|
70
|
+
Change how the user is determined
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
Archer.user = ENV["USER"] # default
|
74
|
+
```
|
75
|
+
|
76
|
+
## Platform Notes
|
77
|
+
|
78
|
+
### Heroku
|
79
|
+
|
80
|
+
For user-specific history, the command should follow this format:
|
81
|
+
|
82
|
+
```sh
|
83
|
+
heroku run USER=andrew rails console
|
84
|
+
```
|
85
|
+
|
86
|
+
Set up an [alias](https://shapeshed.com/unix-alias/) to save yourself some typing
|
87
|
+
|
88
|
+
```sh
|
89
|
+
alias hc="heroku run USER=andrew rails console"
|
90
|
+
```
|
91
|
+
|
92
|
+
### Dokku
|
93
|
+
|
94
|
+
There’s no way to specify a user at the moment.
|
95
|
+
|
96
|
+
## History
|
97
|
+
|
98
|
+
View the [changelog](https://github.com/ankane/archer/blob/master/CHANGELOG.md)
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
103
|
+
|
104
|
+
- [Report bugs](https://github.com/ankane/archer/issues)
|
105
|
+
- Fix bugs and [submit pull requests](https://github.com/ankane/archer/pulls)
|
106
|
+
- Write, clarify, or fix documentation
|
107
|
+
- Suggest or add new features
|
data/lib/archer-rails.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "archer"
|
data/lib/archer.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# dependencies
|
2
|
+
require "active_support/core_ext/module/attribute_accessors"
|
3
|
+
|
4
|
+
# modules
|
5
|
+
require "archer/engine" if defined?(Rails)
|
6
|
+
require "archer/version"
|
7
|
+
|
8
|
+
module Archer
|
9
|
+
autoload :History, "archer/history"
|
10
|
+
|
11
|
+
mattr_accessor :limit
|
12
|
+
self.limit = 200
|
13
|
+
|
14
|
+
mattr_accessor :user
|
15
|
+
self.user = ENV["USER"]
|
16
|
+
|
17
|
+
mattr_accessor :history_file
|
18
|
+
|
19
|
+
def self.clear
|
20
|
+
quietly do
|
21
|
+
Archer::History.where(user: user).delete_all
|
22
|
+
end
|
23
|
+
Readline::HISTORY.clear rescue nil
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.start
|
28
|
+
history = nil
|
29
|
+
begin
|
30
|
+
quietly do
|
31
|
+
history = Archer::History.where(user: user).first_or_initialize
|
32
|
+
end
|
33
|
+
rescue
|
34
|
+
warn "[archer] Create table to enable history"
|
35
|
+
end
|
36
|
+
|
37
|
+
if history && history.persisted?
|
38
|
+
File.write(history_file, history.commands)
|
39
|
+
end
|
40
|
+
|
41
|
+
require "irb/ext/save-history"
|
42
|
+
IRB.conf[:SAVE_HISTORY] = limit
|
43
|
+
IRB.conf[:HISTORY_FILE] = history_file
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.save
|
47
|
+
quietly do
|
48
|
+
history = Archer::History.where(user: user).first_or_initialize
|
49
|
+
history.commands = File.read(history_file)
|
50
|
+
history.save
|
51
|
+
end
|
52
|
+
rescue
|
53
|
+
# do nothing
|
54
|
+
end
|
55
|
+
|
56
|
+
# private
|
57
|
+
def self.quietly
|
58
|
+
ActiveRecord::Base.logger.silence do
|
59
|
+
yield
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# taken from https://github.com/collectiveidea/audited/blob/master/lib/generators/audited/install_generator.rb
|
2
|
+
require "rails/generators"
|
3
|
+
require "rails/generators/migration"
|
4
|
+
require "active_record"
|
5
|
+
require "rails/generators/active_record"
|
6
|
+
|
7
|
+
module Archer
|
8
|
+
module Generators
|
9
|
+
class InstallGenerator < Rails::Generators::Base
|
10
|
+
include Rails::Generators::Migration
|
11
|
+
source_root File.expand_path("../templates", __FILE__)
|
12
|
+
|
13
|
+
# Implement the required interface for Rails::Generators::Migration.
|
14
|
+
def self.next_migration_number(dirname) #:nodoc:
|
15
|
+
next_migration_number = current_migration_number(dirname) + 1
|
16
|
+
if ::ActiveRecord::Base.timestamped_migrations
|
17
|
+
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
18
|
+
else
|
19
|
+
"%.3d" % next_migration_number
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy_migration
|
24
|
+
migration_template "migration.rb", "db/migrate/create_archer_history.rb", migration_version: migration_version
|
25
|
+
end
|
26
|
+
|
27
|
+
def migration_version
|
28
|
+
if rails5?
|
29
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def rails5?
|
34
|
+
Rails::VERSION::MAJOR >= 5
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :archer_history do |t|
|
4
|
+
t.string :user
|
5
|
+
t.text :commands
|
6
|
+
t.timestamp :updated_at
|
7
|
+
end
|
8
|
+
|
9
|
+
add_index :archer_history, :user, unique: true
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: archer-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email: andrew@chartkick.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- CHANGELOG.md
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- lib/archer-rails.rb
|
79
|
+
- lib/archer.rb
|
80
|
+
- lib/archer/engine.rb
|
81
|
+
- lib/archer/history.rb
|
82
|
+
- lib/archer/version.rb
|
83
|
+
- lib/generators/archer/install_generator.rb
|
84
|
+
- lib/generators/archer/templates/migration.rb.tt
|
85
|
+
homepage: https://github.com/ankane/archer
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '2.2'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.7.7
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Rails console history for Heroku, Docker, and more
|
109
|
+
test_files: []
|