archer-rails 0.1.1 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83355041e7d4db676c39d7578272e2ad5b1f485a1d3ce93f19c0ecf997afc270
4
- data.tar.gz: 6dbafdf30bdd43a6866b25f137f3e9c23218d6f756b7f1e31a37f07cf321f5b2
3
+ metadata.gz: 19712b8bc5685ad3770bb596c00281b60ea6c394ec3a748c2874121660d1d90f
4
+ data.tar.gz: 2470e42aa3128bac2e2c59994a0aab8a8bfb04e9887bac37d951dd294e4a1004
5
5
  SHA512:
6
- metadata.gz: 2b4638dcf53e8b2fc7883a992ae5a2234406298ebd7cb2a8d3a4eaf78e06fb81eb80cc7c892b7f8996c4785e7b60a55b702d85655587f4ee4989c7bff4f72f25
7
- data.tar.gz: 4e2da0efaa2218f940ec22d62ef20d5f0747a1b5e63fe15189860306013cbb736440b96bec783d4774bdf5e5886218d908faaaeb60bf2ac5ae1be500a994456d
6
+ metadata.gz: 14bb6c24f59394f76688c4eb75698d6d340a600e04c44f96f5214406cc7489fba74d68c3c4d5e953774915875f535eb2cbce3453f2a664d954308c4625c1395e
7
+ data.tar.gz: 9809857aa33df6b242f104845e1eaa43185e79c28c4177ed7cc6de08750ca0e097cd44c853124b873ea7d1d65aea6b6a343c11d21dc132a8609831a53a6f0f95
data/CHANGELOG.md CHANGED
@@ -1,7 +1,25 @@
1
- ## 0.1.1
1
+ ## 0.2.3 (2021-08-03)
2
+
3
+ - Added `save_session` option
4
+
5
+ ## 0.2.2 (2021-01-07)
6
+
7
+ - Fixed issue with Reline detection
8
+
9
+ ## 0.2.1 (2020-11-23)
10
+
11
+ - Fixed issue with not loading history
12
+ - Use `datetime` type in migration
13
+
14
+ ## 0.2.0 (2020-04-09)
15
+
16
+ - Added support for Reline
17
+ - Dropped support for Rails 4.2
18
+
19
+ ## 0.1.1 (2018-10-23)
2
20
 
3
21
  - Fixed issue with not loading history on Heroku
4
22
 
5
- ## 0.1.0
23
+ ## 0.1.0 (2018-10-23)
6
24
 
7
25
  - First release
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 Andrew Kane
3
+ Copyright (c) 2018-2020 Andrew Kane
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -53,6 +53,14 @@ Archer.user
53
53
 
54
54
  ## Clearing History
55
55
 
56
+ Disable saving history for the current session with:
57
+
58
+ ```ruby
59
+ Archer.save_session = false
60
+ ```
61
+
62
+ You should do this when running sensitive commands.
63
+
56
64
  Clear history for current user with:
57
65
 
58
66
  ```ruby
@@ -105,3 +113,11 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
105
113
  - Fix bugs and [submit pull requests](https://github.com/ankane/archer/pulls)
106
114
  - Write, clarify, or fix documentation
107
115
  - Suggest or add new features
116
+
117
+ To get started with development:
118
+
119
+ ```sh
120
+ git clone https://github.com/ankane/archer.git
121
+ cd archer
122
+ bundle install
123
+ ```
data/lib/archer.rb CHANGED
@@ -3,6 +3,7 @@ require "active_support/core_ext/module/attribute_accessors"
3
3
 
4
4
  # modules
5
5
  require "archer/engine" if defined?(Rails)
6
+ require "archer/irb"
6
7
  require "archer/version"
7
8
 
8
9
  module Archer
@@ -14,13 +15,18 @@ module Archer
14
15
  mattr_accessor :user
15
16
  self.user = ENV["USER"]
16
17
 
18
+ mattr_accessor :save_session
19
+ self.save_session = true
20
+
21
+ # TODO remove in 0.3.0
17
22
  mattr_accessor :history_file
18
23
 
19
24
  def self.clear
20
25
  quietly do
21
26
  Archer::History.where(user: user).delete_all
22
27
  end
23
- Readline::HISTORY.clear
28
+ Readline::HISTORY.clear if defined?(Readline)
29
+ Reline::HISTORY.clear if defined?(Reline)
24
30
  true
25
31
  end
26
32
 
@@ -35,20 +41,34 @@ module Archer
35
41
  end
36
42
 
37
43
  if history
38
- Readline::HISTORY.push(*history.commands.split("\n"))
44
+ commands = history.commands.split("\n")
45
+ history_object.push(*commands)
39
46
  end
40
47
  end
41
48
 
42
49
  def self.save
43
50
  quietly do
44
51
  history = Archer::History.where(user: user).first_or_initialize
45
- history.commands = Readline::HISTORY.to_a.last(limit).join("\n")
46
- history.save
52
+ history.commands = history_object.to_a.last(limit).join("\n")
53
+ history.save!
47
54
  end
48
55
  rescue ActiveRecord::StatementInvalid
49
56
  warn "[archer] Unable to save history"
50
57
  end
51
58
 
59
+ # private
60
+ # TODO use IRB.CurrentContext.io.class::HISTORY
61
+ def self.history_object
62
+ reline? ? Reline::HISTORY : Readline::HISTORY
63
+ end
64
+
65
+ # private
66
+ def self.reline?
67
+ IRB.CurrentContext.io.is_a?(IRB::ReidlineInputMethod)
68
+ rescue
69
+ false
70
+ end
71
+
52
72
  # private
53
73
  def self.quietly
54
74
  ActiveRecord::Base.logger.silence do
data/lib/archer/engine.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  module Archer
2
2
  class Engine < Rails::Engine
3
3
  console do
4
+ # TODO remove in 0.3.0
4
5
  Archer.history_file ||= Rails.root.join("tmp", ".irb-history")
5
- Archer.start
6
+
7
+ # need IRB context to be ready before Archer.start
8
+ ::IRB::Irb.prepend(Archer::Irb)
6
9
 
7
10
  at_exit do
8
- Archer.save
11
+ Archer.save if Archer.save_session
9
12
  end
10
13
  end
11
14
  end
data/lib/archer/irb.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Archer
2
+ module Irb
3
+ # needs to run after conf[:MAIN_CONTEXT] is set
4
+ def eval_input(*)
5
+ Archer.start
6
+ super
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Archer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -1,37 +1,17 @@
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
1
  require "rails/generators/active_record"
6
2
 
7
3
  module Archer
8
4
  module Generators
9
5
  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
6
+ include ActiveRecord::Generators::Migration
7
+ source_root File.join(__dir__, "templates")
22
8
 
23
9
  def copy_migration
24
10
  migration_template "migration.rb", "db/migrate/create_archer_history.rb", migration_version: migration_version
25
11
  end
26
12
 
27
13
  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
14
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
35
15
  end
36
16
  end
37
17
  end
@@ -3,7 +3,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
3
3
  create_table :archer_history do |t|
4
4
  t.string :user
5
5
  t.text :commands
6
- t.timestamp :updated_at
6
+ t.datetime :updated_at
7
7
  end
8
8
 
9
9
  add_index :archer_history, :user, unique: true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archer-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-23 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -16,57 +16,29 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
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
33
+ version: '5'
34
+ type: :runtime
63
35
  prerelease: false
64
36
  version_requirements: !ruby/object:Gem::Requirement
65
37
  requirements:
66
38
  - - ">="
67
39
  - !ruby/object:Gem::Version
68
- version: '0'
69
- description:
40
+ version: '5'
41
+ description:
70
42
  email: andrew@chartkick.com
71
43
  executables: []
72
44
  extensions: []
@@ -79,6 +51,7 @@ files:
79
51
  - lib/archer.rb
80
52
  - lib/archer/engine.rb
81
53
  - lib/archer/history.rb
54
+ - lib/archer/irb.rb
82
55
  - lib/archer/version.rb
83
56
  - lib/generators/archer/install_generator.rb
84
57
  - lib/generators/archer/templates/migration.rb.tt
@@ -86,7 +59,7 @@ homepage: https://github.com/ankane/archer
86
59
  licenses:
87
60
  - MIT
88
61
  metadata: {}
89
- post_install_message:
62
+ post_install_message:
90
63
  rdoc_options: []
91
64
  require_paths:
92
65
  - lib
@@ -94,16 +67,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
67
  requirements:
95
68
  - - ">="
96
69
  - !ruby/object:Gem::Version
97
- version: '2.2'
70
+ version: '2.4'
98
71
  required_rubygems_version: !ruby/object:Gem::Requirement
99
72
  requirements:
100
73
  - - ">="
101
74
  - !ruby/object:Gem::Version
102
75
  version: '0'
103
76
  requirements: []
104
- rubyforge_project:
105
- rubygems_version: 2.7.7
106
- signing_key:
77
+ rubygems_version: 3.2.22
78
+ signing_key:
107
79
  specification_version: 4
108
80
  summary: Rails console history for Heroku, Docker, and more
109
81
  test_files: []