jazz_fingers 5.0.1 → 5.1.0.rc1

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: b393eef001d85320069330c948fdd7236e6e7d7f4de9629d8f840d232fc418ca
4
- data.tar.gz: e7e153cf459ed83b1d6bcb468b8bfb4034e8b10db6de1bdefd9683960024b8ef
3
+ metadata.gz: dfc72ca8fb88d61751cd5452ff6f597d769524e3164e87b9b139ee80c5811513
4
+ data.tar.gz: cde39ec620a826e7a3148d7a8df8e86f033be1692bade1e00c376a92a2f2db41
5
5
  SHA512:
6
- metadata.gz: e2516d198ba0e449a6924c08dbb353d267cecb72dba81bb017fab65e9b23cb27fcd56ec8ce75a4dff4e843626139b0626420822dca7570f04017cd2c7bfbad16
7
- data.tar.gz: 0f8ece831786a3cb2b6a6169f400f0c0b0ebf4822d008889a727d9523e45dee60d2b609092cd2215fa40acf2a23616046d4e3732807901a241ad77c63631f369
6
+ metadata.gz: d17ad8070588368567d2296e6a5c8da63866d71b7e993bdfd96af57dfa59a60d7ec8aade44d0abb65bbae4f7d49e4b3e8c0ebf2de24e775886a8ca8b07cd3c9e
7
+ data.tar.gz: 949d5fb0d2d2e5836185f4f361c486db5e15c3aa6ccca61b3f8b9f97c434aafcc437b5b53613840ebca2c542eceab3ed040511656f9c8d021907579ad5c57104
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.6.6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 5.1.0.rc1 (2020-04-25)
4
+ * Change deprecated method on pry > 0.13.0
5
+ * Improve naming context
6
+
3
7
  ## 5.0.1 (2019-06-02)
4
8
  * Remove documentation for removed dependency
5
9
  * Use non deprecated method of `pry` if existent
@@ -39,10 +39,10 @@ module JazzFingers
39
39
  end
40
40
 
41
41
  def application_name
42
- return "(#{underscore(@application_name)})" unless @application_name.nil?
43
- return "(#{Rails.application.class.parent_name.underscore})" if defined?(Rails)
42
+ return underscore(@application_name) unless @application_name.nil?
43
+ return Rails.application.class.parent_name.underscore if defined?(Rails)
44
44
 
45
- '(jazz_fingers)'
45
+ "jazz_fingers"
46
46
  end
47
47
 
48
48
  private
@@ -1,5 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JazzFingers
2
4
  class Prompt
5
+ OBJECT_INSTANCE = /#<(.+)>/
6
+
7
+ if Pry::VERSION >= "0.13.0"
8
+ require_relative "prompt/pry_version_013_and_later"
9
+ include PryVersion013AndLater
10
+ else
11
+ require_relative "prompt/pry_version_012_and_prior"
12
+ include PryVersion012AndPrior
13
+ end
14
+
3
15
  def initialize(options = {})
4
16
  @colored = options.fetch(:colored)
5
17
  @separator = options.fetch(:separator)
@@ -28,48 +40,75 @@ module JazzFingers
28
40
  "\001\e[1m\002#{text}\001\e[0m\002"
29
41
  end
30
42
 
31
- def separator
43
+ def main_separator
32
44
  red_text(@separator)
33
45
  end
34
46
 
35
- def name
36
- blue_text(@application_name)
47
+ def wait_separator
48
+ "*"
37
49
  end
38
50
 
39
- def line_number(pry)
40
- if pry.respond_to? :input_ring
41
- "[#{bold_text(pry.input_ring.size)}]"
42
- else
43
- "[#{bold_text(pry.input_array.size)}]"
44
- end
45
- end
51
+ # Return the current Pry context
52
+ #
53
+ # When the Pry context is `"main"` or `"nil"`, use the application name from
54
+ # the JazzFingers config. Examples: "(my_rails_app_name)", "(jazz_fingers)".
55
+ #
56
+ # When in the context of an object instance, use the abbreviated object
57
+ # path. Example: "(#<Pry::Prompt>)", "(#<RSpec::...::ClassName>)"
58
+ #
59
+ # Fall back to the raw context provided by Pry.view_clip.
60
+ # Example: "(Pry::Prompt)"
61
+ def context(module_name = "main")
62
+ name =
63
+ case module_name
64
+ when "main", "nil"
65
+ @application_name
66
+ when OBJECT_INSTANCE
67
+ abbreviated_context(module_name)
68
+ else
69
+ module_name
70
+ end
46
71
 
47
- def text(object, level)
48
- level = 0 if level < 0
49
- text = Pry.view_clip(object)
72
+ blue_text("(#{name})")
73
+ end
50
74
 
51
- if text == 'main'
52
- ''
75
+ def line_number(pry)
76
+ if pry.respond_to? :input_ring
77
+ bold_text(pry.input_ring.size)
53
78
  else
54
- "(#{'../' * level}#{text})"
79
+ bold_text(pry.input_array.size)
55
80
  end
56
81
  end
57
82
 
58
- def main_prompt
59
- lambda do |_object, _level, pry|
60
- "#{RUBY_VERSION} #{name}#{line_number(pry)} #{separator} "
61
- end
62
- end
83
+ # Abbreviate the object path in the given `object_label` string so the
84
+ # prompt doesn't overflow. Display only the root and leaf namespaces.
85
+ #
86
+ # Examples:
87
+ # In: #<Class1::Class2::Class3::Class4::Class5>
88
+ # Out: #<Class1::...::Class5>
89
+ #
90
+ # In: #<Class1::Class2>
91
+ # Out: #<Class1::Class2>
92
+ #
93
+ # In: #<NoPathJustASingleLongClassName>
94
+ # Out: #<NoPathJustASingleLongClassName>
95
+ def abbreviated_context(object_label)
96
+ object_path = object_label[OBJECT_INSTANCE, 1]
97
+ object_path_components = object_path.split("::")
98
+ return object_label if object_path_components.length <= 2
63
99
 
64
- def block_prompt
65
- lambda do |_object, level, pry|
66
- spaces = ' ' * level
67
- "#{RUBY_VERSION} #{name}#{line_number(pry)} * #{spaces}"
68
- end
100
+ root, *_, leaf = object_path_components
101
+ "#<#{root}::...::#{leaf}>"
69
102
  end
70
103
 
71
- def config
72
- [main_prompt, block_prompt]
104
+ def template(module_name, pry, separator)
105
+ format(
106
+ "%<ruby>s %<context>s[%<line>s] %<separator>s ",
107
+ ruby: RUBY_VERSION,
108
+ context: context(module_name),
109
+ line: line_number(pry),
110
+ separator: separator
111
+ )
73
112
  end
74
113
  end
75
114
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JazzFingers
4
+ class Prompt
5
+ # For Pry < 0.13.
6
+ module PryVersion012AndPrior
7
+ def config
8
+ [main_prompt, wait_prompt]
9
+ end
10
+
11
+ def main_prompt
12
+ lambda do |context, _nesting, pry|
13
+ template(Pry.view_clip(context), pry, main_separator)
14
+ end
15
+ end
16
+
17
+ def wait_prompt
18
+ lambda do |context, _nesting, pry|
19
+ template(Pry.view_clip(context), pry, wait_separator)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JazzFingers
4
+ class Prompt
5
+ # For Pry >= 0.13.
6
+ module PryVersion013AndLater
7
+ # Add the JazzFingers prompt to the Pry::Prompt hash to enable changing it
8
+ # with `change-prompt`.
9
+ #
10
+ # Return the Pry::Prompt object.
11
+ def config
12
+ return Pry::Prompt[:jazz_fingers] if Pry::Prompt[:jazz_fingers]
13
+
14
+ Pry::Prompt.add(
15
+ :jazz_fingers,
16
+ "A spruced-up prompt provided by jazz_fingers.",
17
+ [main_separator, wait_separator]
18
+ ) do |context, _nesting, pry, separator|
19
+ template(Pry.view_clip(context), pry, separator)
20
+ end
21
+
22
+ Pry::Prompt[:jazz_fingers]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module JazzFingers
2
- VERSION = '5.0.1'.freeze
2
+ VERSION = '5.1.0.rc1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jazz_fingers
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Henrique Lopes Ribeiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-02 00:00:00.000000000 Z
11
+ date: 2020-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -106,6 +106,8 @@ files:
106
106
  - lib/jazz_fingers/input.rb
107
107
  - lib/jazz_fingers/print.rb
108
108
  - lib/jazz_fingers/prompt.rb
109
+ - lib/jazz_fingers/prompt/pry_version_012_and_prior.rb
110
+ - lib/jazz_fingers/prompt/pry_version_013_and_later.rb
109
111
  - lib/jazz_fingers/version.rb
110
112
  homepage: https://github.com/plribeiro3000/jazz_fingers
111
113
  licenses:
@@ -122,11 +124,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
124
  version: '2.0'
123
125
  required_rubygems_version: !ruby/object:Gem::Requirement
124
126
  requirements:
125
- - - ">="
127
+ - - ">"
126
128
  - !ruby/object:Gem::Version
127
- version: '0'
129
+ version: 1.3.1
128
130
  requirements: []
129
- rubygems_version: 3.0.3
131
+ rubygems_version: 3.0.8
130
132
  signing_key:
131
133
  specification_version: 4
132
134
  summary: Exercise those fingers. Pry-based enhancements for the default Ruby console.