jazz_fingers 5.0.0 → 5.2.2

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
- SHA1:
3
- metadata.gz: 4999936c5383de2179cf7bc5d77a6fd222d3de26
4
- data.tar.gz: cb9a42ec388dcf1a9350ec07819d884562f5e25e
2
+ SHA256:
3
+ metadata.gz: 23ec179734e2fa4ef28b3352075a7c54557f406907fb287818e5df935865dccf
4
+ data.tar.gz: a2d70183f7ab4d41f952d2b325ddab9b1bd4ebf52b398626def3c7d60f3dec69
5
5
  SHA512:
6
- metadata.gz: 0e7754ab8b9f32c1219e1841d1c5345f3d2a6956ab6f5ef42a9de2c2e315ae864db7ba95d5894648a52640b1dae63d711814977e95e0f954e26ae0348cbddae0
7
- data.tar.gz: fb570df06f4a74a8d2c93d3773ad883f8a40a1e93a33dd0b761a5b329d3fa3892e753420ce38929bb1f48259dcca2c30a63925830dfb98d6ca01656764801ecb
6
+ metadata.gz: 86bd06b63b658828bfcf6f27986a0c89e5419bee9cf31a42b38d8d8c3135e9bdff0e0a224fce62d96da1ff49aff05c2490403228d5953b830e107e9506c83036
7
+ data.tar.gz: 2d3e975c8686f6b1936f3501a60a10e429fcee142cb48672797385f5b673039f6dd8edbeb34fe3e490ff4ea8122186844369e3b8fc2dd82485569de736c400f4
@@ -0,0 +1 @@
1
+ .rubocop.yml
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.6.6
@@ -1,5 +1,13 @@
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
+
7
+ ## 5.0.1 (2019-06-02)
8
+ * Remove documentation for removed dependency
9
+ * Use non deprecated method of `pry` if existent
10
+
3
11
  ## 5.0.0 (2018-05-02)
4
12
  * Remove [pry-doc][pry-doc] dependency to reduce memory footprint
5
13
  * Remove [hirb][hirb] dependency since its not being actively maintained
data/README.md CHANGED
@@ -32,8 +32,6 @@ end
32
32
 
33
33
  That's it. Run `pry` as usual.
34
34
 
35
- [Hirb][hirb] isn't enabled by default. To use, run `Hirb.enable` in the console.
36
-
37
35
  Ruby compiled against a proper readline library, ideally GNU readline, is
38
36
  recommended. Alternatively, [`gem install rb-readline`][rb-readline] for an
39
37
  acceptible backup. Using ruby compiled against a `libedit` wrapper (primarily OS
@@ -6,6 +6,9 @@ require 'readline'
6
6
  require 'forwardable'
7
7
 
8
8
  module JazzFingers
9
+ autoload :AWESOME_PRINT, 'jazz_fingers/awesome_print'
10
+ autoload :CodeRay, 'jazz_fingers/coderay'
11
+ autoload :Commands, 'jazz_fingers/commands'
9
12
  autoload :Configuration, 'jazz_fingers/configuration'
10
13
  autoload :Input, 'jazz_fingers/input'
11
14
  autoload :Print, 'jazz_fingers/print'
@@ -45,13 +48,32 @@ module JazzFingers
45
48
  end
46
49
 
47
50
  def setup!
48
- Pry.print = print if JazzFingers.awesome_print?
49
51
  Pry.prompt = prompt
50
52
  Pry.input = input if JazzFingers.coolline?
51
53
  Pry.config.should_load_plugins = false
52
54
  Pry.commands.alias_command('c', 'continue')
53
55
  Pry.commands.alias_command('s', 'step')
54
56
  Pry.commands.alias_command('n', 'next')
57
+ Pry.editor = 'vi'
58
+ Pry.config.ls.separator = "\n"
59
+ Pry.config.ls.heading_color = :magenta
60
+ Pry.config.ls.public_method_color = :green
61
+ Pry.config.ls.protected_method_color = :yellow
62
+ Pry.config.ls.private_method_color = :bright_black
63
+
64
+ JazzFingers::Commands.constants(false).each do |constant|
65
+ command = JazzFingers::Commands.const_get(constant)
66
+ Pry.config.commands.import(command)
67
+ end
68
+
69
+ if JazzFingers.awesome_print?
70
+ require 'awesome_print'
71
+
72
+ AwesomePrint.defaults = JazzFingers::AWESOME_PRINT
73
+ Pry.print = print
74
+ end
75
+
76
+ JazzFingers::CodeRay.setup!
55
77
 
56
78
  true
57
79
  end
@@ -0,0 +1,26 @@
1
+ module JazzFingers
2
+ AWESOME_PRINT = {
3
+ indent: 2,
4
+ sort_keys: true,
5
+ color: {
6
+ args: :greenish,
7
+ array: :pale,
8
+ bigdecimal: :blue,
9
+ class: :yellow,
10
+ date: :greenish,
11
+ falseclass: :red,
12
+ fixnum: :blue,
13
+ float: :blue,
14
+ hash: :pale,
15
+ keyword: :cyan,
16
+ method: :purpleish,
17
+ nilclass: :red,
18
+ string: :yellowish,
19
+ struct: :pale,
20
+ symbol: :cyanish,
21
+ time: :greenish,
22
+ trueclass: :green,
23
+ variable: :cyanish
24
+ }
25
+ }
26
+ end
@@ -0,0 +1,20 @@
1
+ module JazzFingers
2
+ module CodeRay
3
+ autoload :ESCAPED_COLORS, 'jazz_fingers/coderay/escaped_colors'
4
+ autoload :UNESCAPED_COLORS, 'jazz_fingers/coderay/unescaped_colors'
5
+
6
+ def self.setup!
7
+ ::CodeRay.scan("example", :ruby).term
8
+
9
+ if ::CodeRay::VERSION >= '1.1.0'
10
+ ESCAPED_COLORS.each do |key, value|
11
+ ::CodeRay::Encoders::Terminal::TOKEN_COLORS[key] = value
12
+ end
13
+ else
14
+ UNESCAPED_COLORS.each do |key, value|
15
+ ::CodeRay::Encoders::Terminal::TOKEN_COLORS[key] = value
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,74 @@
1
+ module JazzFingers
2
+ module CodeRay
3
+ ESCAPED_COLORS = {
4
+ attribute_name: "\e[33m",
5
+ attribute_value: "\e[31m",
6
+ binary: "\e[1;35m",
7
+ char: {
8
+ self: "\e[36m",
9
+ delimiter: "\e[34m"
10
+ },
11
+ class: "\e[1;35m",
12
+ class_variable: "\e[36m",
13
+ color: "\e[32m",
14
+ comment: "\e[37m",
15
+ complex: "\e[34m",
16
+ constant: "\e[34m\e[4m",
17
+ decoration: "\e[35m",
18
+ definition: "\e[1;32m",
19
+ directive: "\e[32m\e[4m",
20
+ doc: "\e[46m",
21
+ doctype: "\e[1;30m",
22
+ doc_string: "\e[31m\e[4m",
23
+ entity: "\e[33m",
24
+ error: "\e[1;33m\e[41m",
25
+ exception: "\e[1;31m",
26
+ float: "\e[1;35m",
27
+ function: "\e[1;34m",
28
+ global_variable: "\e[42m",
29
+ hex: "\e[1;36m",
30
+ include: "\e[33m",
31
+ integer: "\e[1;34m",
32
+ key: "\e[35m",
33
+ label: "\e[1;15m",
34
+ local_variable: "\e[33m",
35
+ octal: "\e[1;35m",
36
+ operator_name: "\e[1;29m",
37
+ predefined_constant: "\e[1;36m",
38
+ predefined_type: "\e[1;30m",
39
+ predefined: "\e[4m\e[1;34m",
40
+ preprocessor: "\e[36m",
41
+ pseudo_class: "\e[34m",
42
+ regexp: {
43
+ self: "\e[31m",
44
+ content: "\e[31m",
45
+ delimiter: "\e[1;29m",
46
+ modifier: "\e[35m",
47
+ function: "\e[1;29m"
48
+ },
49
+ reserved: "\e[1;31m",
50
+ shell: {
51
+ self: "\e[42m",
52
+ content: "\e[1;29m",
53
+ delimiter: "\e[37m",
54
+ },
55
+ string: {
56
+ self: "\e[36m",
57
+ modifier: "\e[1;32m",
58
+ escape: "\e[1;36m",
59
+ delimiter: "\e[1;32m",
60
+ },
61
+ symbol: "\e[1;31m",
62
+ tag: "\e[34m",
63
+ type: "\e[1;34m",
64
+ value: "\e[36m",
65
+ variable: "\e[34m",
66
+
67
+ insert: "\e[42m",
68
+ delete: "\e[41m",
69
+ change: "\e[44m",
70
+ head: "\e[45m"
71
+ }.freeze
72
+ end
73
+ end
74
+
@@ -0,0 +1,74 @@
1
+ module JazzFingers
2
+ module CodeRay
3
+ UNESCAPED_COLORS = {
4
+ attribute_name: '33',
5
+ attribute_value: '31',
6
+ binary: '1;35',
7
+ char: {
8
+ self: '36',
9
+ delimiter: '34'
10
+ },
11
+ class: '1;35',
12
+ class_variable: '36',
13
+ color: '32',
14
+ comment: '37',
15
+ complex: '34',
16
+ constant: ['34', '4'],
17
+ decoration: '35',
18
+ definition: '1;32',
19
+ directive: ['32', '4'],
20
+ doc: '46',
21
+ doctype: '1;30',
22
+ doc_string: ['31', '4'],
23
+ entity: '33',
24
+ error: ['1;33', '41'],
25
+ exception: '1;31',
26
+ float: '1;35',
27
+ function: '1;34',
28
+ global_variable: '42',
29
+ hex: '1;36',
30
+ include: '33',
31
+ integer: '1;34',
32
+ key: '35',
33
+ label: '1;15',
34
+ local_variable: '33',
35
+ octal: '1;35',
36
+ operator_name: '1;29',
37
+ predefined_constant: '1;36',
38
+ predefined_type: '1;30',
39
+ predefined: ['4', '1;34'],
40
+ preprocessor: '36',
41
+ pseudo_class: '34',
42
+ regexp: {
43
+ self: '31',
44
+ content: '31',
45
+ delimiter: '1;29',
46
+ modifier: '35',
47
+ function: '1;29'
48
+ },
49
+ reserved: '1;31',
50
+ shell: {
51
+ self: '42',
52
+ content: '1;29',
53
+ delimiter: '37',
54
+ },
55
+ string: {
56
+ self: '36',
57
+ modifier: '1;32',
58
+ escape: '1;36',
59
+ delimiter: '1;32',
60
+ },
61
+ symbol: '1;31',
62
+ tag: '34',
63
+ type: '1;34',
64
+ value: '36',
65
+ variable: '34',
66
+
67
+ insert: '42',
68
+ delete: '41',
69
+ change: '44',
70
+ head: '45'
71
+ }.freeze
72
+ end
73
+ end
74
+
@@ -0,0 +1,7 @@
1
+ module JazzFingers
2
+ module Commands
3
+ autoload :CALLER_METHOD, 'jazz_fingers/commands/caller_method'
4
+ autoload :COPY, 'jazz_fingers/commands/copy'
5
+ autoload :SQL, 'jazz_fingers/commands/sql'
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ module JazzFingers
2
+ module Commands
3
+ CALLER_METHOD = Pry::CommandSet.new do
4
+ command "caller_method" do |depth|
5
+ depth = depth.to_i || 1
6
+ if /^(.+?):(\d+)(?::in `(.*)')?/ =~ caller(depth+1).first
7
+ file = Regexp.last_match[1]
8
+ line = Regexp.last_match[2].to_i
9
+ method = Regexp.last_match[3]
10
+ output.puts [file, line, method]
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,10 @@
1
+ module JazzFingers
2
+ module Commands
3
+ COPY = Pry::CommandSet.new do
4
+ command "copy", "Copy argument to the clip-board" do |str|
5
+ IO.popen('pbcopy', 'w') { |f| f << str.to_s }
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,14 @@
1
+ module JazzFingers
2
+ module Commands
3
+ SQL = Pry::CommandSet.new do
4
+ command "sql", "Send sql over AR." do |query|
5
+ if defined?(Rails)
6
+ pp ActiveRecord::Base.connection.select_all(query)
7
+ else
8
+ pp "Rails not defined"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -39,10 +39,19 @@ 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?
44
43
 
45
- '(jazz_fingers)'
44
+ if defined?(Rails)
45
+ application_class = Rails.application.class
46
+
47
+ if application_class.respond_to?(:module_parent_name)
48
+ return application_class.module_parent_name.underscore
49
+ else
50
+ return application_class.parent_name.underscore
51
+ end
52
+ end
53
+
54
+ "jazz_fingers"
46
55
  end
47
56
 
48
57
  private
@@ -5,7 +5,7 @@ module JazzFingers
5
5
  class << self
6
6
  def config
7
7
  lambda do |_output, value, pry_object|
8
- pretty = value.ai(indent: 2)
8
+ pretty = value.ai
9
9
  pry_object.pager.page("=> #{pretty}\n")
10
10
  end
11
11
  end
@@ -1,5 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JazzFingers
2
4
  class Prompt
5
+ OBJECT_INSTANCE = /#<(.+)>/
6
+
7
+ autoload :PryVersion013AndLater, 'jazz_fingers/prompt/pry_version_013_and_later'
8
+ autoload :PryVersion012AndPrior, 'jazz_fingers/prompt/pry_version_012_and_prior'
9
+
10
+ if Pry::VERSION >= "0.13.0"
11
+ include PryVersion013AndLater
12
+ else
13
+ include PryVersion012AndPrior
14
+ end
15
+
3
16
  def initialize(options = {})
4
17
  @colored = options.fetch(:colored)
5
18
  @separator = options.fetch(:separator)
@@ -28,44 +41,75 @@ module JazzFingers
28
41
  "\001\e[1m\002#{text}\001\e[0m\002"
29
42
  end
30
43
 
31
- def separator
44
+ def main_separator
32
45
  red_text(@separator)
33
46
  end
34
47
 
35
- def name
36
- blue_text(@application_name)
48
+ def wait_separator
49
+ "*"
37
50
  end
38
51
 
39
- def line_number(pry)
40
- "[#{bold_text(pry.input_array.size)}]"
41
- end
52
+ # Return the current Pry context
53
+ #
54
+ # When the Pry context is `"main"` or `"nil"`, use the application name from
55
+ # the JazzFingers config. Examples: "(my_rails_app_name)", "(jazz_fingers)".
56
+ #
57
+ # When in the context of an object instance, use the abbreviated object
58
+ # path. Example: "(#<Pry::Prompt>)", "(#<RSpec::...::ClassName>)"
59
+ #
60
+ # Fall back to the raw context provided by Pry.view_clip.
61
+ # Example: "(Pry::Prompt)"
62
+ def context(module_name = "main")
63
+ name =
64
+ case module_name
65
+ when "main", "nil"
66
+ @application_name
67
+ when OBJECT_INSTANCE
68
+ abbreviated_context(module_name)
69
+ else
70
+ module_name
71
+ end
42
72
 
43
- def text(object, level)
44
- level = 0 if level < 0
45
- text = Pry.view_clip(object)
73
+ blue_text("(#{name})")
74
+ end
46
75
 
47
- if text == 'main'
48
- ''
76
+ def line_number(pry)
77
+ if pry.respond_to? :input_ring
78
+ bold_text(pry.input_ring.size)
49
79
  else
50
- "(#{'../' * level}#{text})"
80
+ bold_text(pry.input_array.size)
51
81
  end
52
82
  end
53
83
 
54
- def main_prompt
55
- lambda do |_object, _level, pry|
56
- "#{RUBY_VERSION} #{name}#{line_number(pry)} #{separator} "
57
- end
58
- end
84
+ # Abbreviate the object path in the given `object_label` string so the
85
+ # prompt doesn't overflow. Display only the root and leaf namespaces.
86
+ #
87
+ # Examples:
88
+ # In: #<Class1::Class2::Class3::Class4::Class5>
89
+ # Out: #<Class1::...::Class5>
90
+ #
91
+ # In: #<Class1::Class2>
92
+ # Out: #<Class1::Class2>
93
+ #
94
+ # In: #<NoPathJustASingleLongClassName>
95
+ # Out: #<NoPathJustASingleLongClassName>
96
+ def abbreviated_context(object_label)
97
+ object_path = object_label[OBJECT_INSTANCE, 1]
98
+ object_path_components = object_path.split("::")
99
+ return object_label if object_path_components.length <= 2
59
100
 
60
- def block_prompt
61
- lambda do |_object, level, pry|
62
- spaces = ' ' * level
63
- "#{RUBY_VERSION} #{name}#{line_number(pry)} * #{spaces}"
64
- end
101
+ root, *_, leaf = object_path_components
102
+ "#<#{root}::...::#{leaf}>"
65
103
  end
66
104
 
67
- def config
68
- [main_prompt, block_prompt]
105
+ def template(module_name, pry, separator)
106
+ format(
107
+ "%<ruby>s %<context>s[%<line>s] %<separator>s ",
108
+ ruby: RUBY_VERSION,
109
+ context: context(module_name),
110
+ line: line_number(pry),
111
+ separator: separator
112
+ )
69
113
  end
70
114
  end
71
115
  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.0'.freeze
2
+ VERSION = '5.2.2'.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.0
4
+ version: 5.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Henrique Lopes Ribeiro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -102,16 +102,26 @@ files:
102
102
  - Rakefile
103
103
  - jazz_fingers.gemspec
104
104
  - lib/jazz_fingers.rb
105
+ - lib/jazz_fingers/awesome_print.rb
106
+ - lib/jazz_fingers/coderay.rb
107
+ - lib/jazz_fingers/coderay/escaped_colors.rb
108
+ - lib/jazz_fingers/coderay/unescaped_colors.rb
109
+ - lib/jazz_fingers/commands.rb
110
+ - lib/jazz_fingers/commands/caller_method.rb
111
+ - lib/jazz_fingers/commands/copy.rb
112
+ - lib/jazz_fingers/commands/sql.rb
105
113
  - lib/jazz_fingers/configuration.rb
106
114
  - lib/jazz_fingers/input.rb
107
115
  - lib/jazz_fingers/print.rb
108
116
  - lib/jazz_fingers/prompt.rb
117
+ - lib/jazz_fingers/prompt/pry_version_012_and_prior.rb
118
+ - lib/jazz_fingers/prompt/pry_version_013_and_later.rb
109
119
  - lib/jazz_fingers/version.rb
110
120
  homepage: https://github.com/plribeiro3000/jazz_fingers
111
121
  licenses:
112
122
  - MIT
113
123
  metadata: {}
114
- post_install_message:
124
+ post_install_message:
115
125
  rdoc_options: []
116
126
  require_paths:
117
127
  - lib
@@ -126,9 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
136
  - !ruby/object:Gem::Version
127
137
  version: '0'
128
138
  requirements: []
129
- rubyforge_project:
130
- rubygems_version: 2.4.6
131
- signing_key:
139
+ rubygems_version: 3.1.3
140
+ signing_key:
132
141
  specification_version: 4
133
142
  summary: Exercise those fingers. Pry-based enhancements for the default Ruby console.
134
143
  test_files: []
data/.hound.yml DELETED
@@ -1,5 +0,0 @@
1
- Metrics/LineLength:
2
- Max: 120
3
-
4
- Style/Documentation:
5
- Enabled: false