rails_env_prompt 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c52c247346b9f37d8c766f78cbefd1b09f86a81a7178c35d783252314075ea9
4
- data.tar.gz: 438890789491f250be29ac4d0673c2ed4ccb750a0ab483726b18842706aad9b0
3
+ metadata.gz: 38a8d4d69de6506f630f17bf0d4427246bce8640d280ccf3a765568a0ab2e4e3
4
+ data.tar.gz: 27237e643cf7b905e664ba67d1a88fe5988c5f8387fe9e07e059f932eb9254f2
5
5
  SHA512:
6
- metadata.gz: 05bbe43b291cbc3ce8b220b204378ef6d938b2803e905960dcfd826ee32a4c4d4e295a0f4788b3684939cc0ea6a0ce3afddfcdfd4719d7bdcc0ad33f1f9797f9
7
- data.tar.gz: a1f5c1da2d5ce4feb3f88540c9e267821594de20f6f7ad624ec035b33a82e3977a084a344326f75d97646135e1f5bd7d41fcc44b85aa674fce8cc3ed2f67f3b5
6
+ metadata.gz: 764346be500386598dffbcf9f42df420cd8e8fcbd6efbd3c221d997d49714bdc65c1f801bafc0bfa65b973afe2e074b66b1d02fc6bd84bc1c16ee3068b0f39f2
7
+ data.tar.gz: ab9737443f7ef3f543706e3a09475d289b45248e6aabe91d590cdd9eb6e879ceedeb911b529899b6a363bb4cc1cc12fb9723348e9c86afde46e312c21df1b811
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_env_prompt (1.0.3)
4
+ rails_env_prompt (1.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,15 @@
1
+ require 'irb'
2
+
3
+ if IRB::VERSION >= Gem::Version.new('1.9.0')
4
+ module IRB
5
+ class Irb
6
+ original_format_prompt = instance_method(:format_prompt)
7
+
8
+ define_method(:format_prompt) do |format, ltype, indent, line_no|
9
+ original_format_prompt.bind(self).(
10
+ "#{RailsEnvPrompt.to_s} #{format}", ltype, indent, line_no
11
+ )
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ require 'irb'
2
+
3
+ if IRB::VERSION < Gem::Version.new('1.9.0')
4
+ module IRB
5
+ class << self
6
+ def _patch
7
+ prompt = RailsEnvPrompt.template
8
+
9
+ prompts = {
10
+ normal: "#{prompt} %03n:%i> ",
11
+ for_continuated_strings: "#{prompt} %03n:%i%l ",
12
+ for_continuated_statements: "#{prompt} %03n:%i* "
13
+ }
14
+
15
+ # Some older versions store this value and call dup. We'll have to change it each time to have it include current
16
+ # tenant and possible other dynamic variables
17
+ %i[normal for_continuated_strings for_continuated_statements].each do |key|
18
+ prompts[key] = prompts[key].tap do |string|
19
+ def string.dup
20
+ RailsEnvPrompt.parse(self)
21
+ end
22
+ end
23
+ end
24
+
25
+ IRB.conf[:PROMPT][:RAILS_ENV_PROMPT] = {
26
+ PROMPT_I: prompts[:normal],
27
+ PROMPT_N: prompts[:normal],
28
+ PROMPT_S: prompts[:for_continuated_strings],
29
+ PROMPT_C: prompts[:for_continuated_statements],
30
+ RETURN: "=> %s\n"
31
+ }
32
+
33
+ IRB.conf[:PROMPT_MODE] = :RAILS_ENV_PROMPT
34
+ end
35
+
36
+ _setup = instance_method(:setup)
37
+
38
+ if _setup.arity == -2
39
+ define_method(:setup) do |ap_path, argv: ::ARGV|
40
+ _setup.bind(self).call(ap_path, argv: argv)
41
+ _patch
42
+ end
43
+ else
44
+ define_method(:setup) do |ap_path|
45
+ _setup.bind(self).call(ap_path)
46
+ _patch
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -5,6 +5,6 @@ end
5
5
 
6
6
  if defined?(Pry)
7
7
  Pry.config.prompt = proc do |obj, nest_level, _|
8
- "#{RailsEnvPrompt.template} #{obj}:#{nest_level}> "
8
+ "#{RailsEnvPrompt.to_s} #{obj}:#{nest_level}> "
9
9
  end
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module RailsEnvPrompt
2
- VERSION = '1.0.4'.freeze
2
+ VERSION = '1.0.5'.freeze
3
3
  end
@@ -1,16 +1,6 @@
1
- require 'rails_env_prompt/irb'
2
- require 'rails_env_prompt/pry'
3
1
  require 'rails_env_prompt/version'
4
2
 
5
3
  module RailsEnvPrompt
6
- def self.template
7
- [
8
- app_name,
9
- environment_name,
10
- tenant_prompt
11
- ].compact.join('/') + ' '
12
- end
13
-
14
4
  def self.app_name
15
5
  @app_name ||= begin
16
6
  application_class = Rails.application.class
@@ -23,14 +13,28 @@ module RailsEnvPrompt
23
13
  end
24
14
  end
25
15
 
26
- def self.environment_name
27
- colored(Rails.env, environment_color)
16
+ def self.template
17
+ [
18
+ '[APP]',
19
+ '[ENV]',
20
+ tenant_prompt
21
+ ].compact.join('/')
22
+ end
23
+
24
+ def self.parse(string)
25
+ string.gsub('[APP]', app_name)
26
+ .gsub('[ENV]', colored(Rails.env, environment_color))
27
+ .gsub('[TENANT]', defined?(Apartment) ? Apartment::Tenant.current : '')
28
+ end
29
+
30
+ def self.to_s
31
+ parse(template)
28
32
  end
29
33
 
30
34
  def self.tenant_prompt
31
35
  return unless defined?(Apartment)
32
36
 
33
- Apartment::Tenant.current
37
+ '[TENANT]'
34
38
  end
35
39
 
36
40
  def self.colored(text, color)
@@ -45,3 +49,8 @@ module RailsEnvPrompt
45
49
  end
46
50
  end
47
51
  end
52
+
53
+ # Load patches
54
+ require 'rails_env_prompt/irb-pre-190'
55
+ require 'rails_env_prompt/irb-190'
56
+ require 'rails_env_prompt/pry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_env_prompt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rene van Lieshout
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-14 00:00:00.000000000 Z
11
+ date: 2024-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -51,7 +51,8 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - lib/rails_env_prompt.rb
54
- - lib/rails_env_prompt/irb.rb
54
+ - lib/rails_env_prompt/irb-190.rb
55
+ - lib/rails_env_prompt/irb-pre-190.rb
55
56
  - lib/rails_env_prompt/pry.rb
56
57
  - lib/rails_env_prompt/version.rb
57
58
  - rails_env_prompt.gemspec
@@ -74,8 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  requirements: []
77
- rubyforge_project:
78
- rubygems_version: 2.7.6.3
78
+ rubygems_version: 3.1.2
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Adds current Rails env and Apartment tenant to prompt
@@ -1,34 +0,0 @@
1
- require 'irb'
2
-
3
- module IRB
4
- class << self
5
- def _patch
6
- template = RailsEnvPrompt.template
7
-
8
- current_prompt = IRB.conf[:PROMPT_MODE]
9
-
10
- IRB.conf[:PROMPT][:RAILS_ENV_PROMPT] = IRB.conf[:PROMPT][:DEFAULT].map do |key, value|
11
- [
12
- key,
13
- (template + value)
14
- ]
15
- end.to_h
16
-
17
- IRB.conf[:PROMPT_MODE] = :RAILS_ENV_PROMPT
18
- end
19
-
20
- _setup = instance_method(:setup)
21
-
22
- if _setup.arity == -2
23
- define_method(:setup) do |ap_path, argv: ::ARGV|
24
- _setup.bind(self).call(ap_path, argv: argv)
25
- _patch
26
- end
27
- else
28
- define_method(:setup) do |ap_path|
29
- _setup.bind(self).call(ap_path)
30
- _patch
31
- end
32
- end
33
- end
34
- end