lit-cli 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/config.rb +6 -6
  3. data/lib/lit_pry.rb +77 -51
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 839f03037b67dd56c7b7d4c38ba26138082594823cc32dbc7217c78363d34088
4
- data.tar.gz: 3ab13437fcb2e6884ccd9465d85c72c0f3f7623b2e4076cd21ea22ba369a160b
3
+ metadata.gz: 39a417c815a30ecdf0e99aaa9aa47d22b4def3f2d891f6da1911414a7187a86b
4
+ data.tar.gz: 5bb7af898274544027202aedb33d9428401044867ad0693ae6314b1c361c9418
5
5
  SHA512:
6
- metadata.gz: 97d737397a07cfd123166f9c233757e0db4606072c75f22235c85d421474bc05bf94ef2ec8e216420b3c1cca9aecd1615c9ad20ade4b76ee6dde3770d36ba89f
7
- data.tar.gz: 7e832c959dd947b99609f2e0ff8e30bb45a8f117b13a617a4671bb4236ee6a1a455f595b8eb35d9d682bc06abe9411e336b2f82553e328cd574215481b565770
6
+ metadata.gz: 1b45c6ae31e1db4cf3ac3fd338e8a11df273618cd8aa8b7d870d3764c9ae86b472b5823504fec11956c33fcc7fe0ca044db544e6c872f167a9db7bbfeaf881b5
7
+ data.tar.gz: 47a8560f08cbd269877dcd1a6bd14b718a684b190991b80b439602fe766b15f84bc1c44826aafed8416277e2fb425f66d35d447f32676cacdc8d9ef4fa31a8a0
data/lib/config.rb CHANGED
@@ -33,12 +33,12 @@ module LitCLI
33
33
  def initialize()
34
34
 
35
35
  @statuses = {
36
- :info => { icon: "ℹ", color: :blue },
37
- :pass => { icon: "✔", color: :green },
38
- :warn => { icon: "⚠", color: :yellow },
39
- :fail => { icon: "⨯", color: :red },
40
- :error => { icon: "!", color: :red },
41
- :debug => { icon: "?", color: :purple },
36
+ :info => { icon: "ℹ", color: :blue, styles: [:upcase] },
37
+ :pass => { icon: "✔", color: :green, styles: [:upcase] },
38
+ :warn => { icon: "⚠", color: :yellow, styles: [:upcase] },
39
+ :fail => { icon: "⨯", color: :red, styles: [:upcase] },
40
+ :error => { icon: "!", color: :red, styles: [:upcase] },
41
+ :debug => { icon: "?", color: :purple, styles: [:upcase] },
42
42
  }
43
43
 
44
44
  @types = nil
data/lib/lit_pry.rb CHANGED
@@ -1,70 +1,96 @@
1
1
  # Only override kernel methods when Lit's @step flag is true.
2
2
  if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
3
+ require 'set'
4
+
5
+ # TODO: Investigate RubyGems `require` before overriding.
6
+ # SEE: https://github.com/ruby/ruby/blob/v2_6_3/lib/rubygems/core_ext/kernel_require.rb
7
+
3
8
  module Kernel
4
9
 
5
- def require_relative relative_path
6
- filename = relative_path
10
+ @@lit_processed_paths = Set.new
7
11
 
8
- # Get directory of the file that called this file.
9
- absolute_path = caller_locations.first.absolute_path.split('/')
10
- absolute_path.pop
12
+ def require_relative relative_path, current_directory = nil
13
+ return false if relative_path.nil?
11
14
 
12
- # When relative path is current directory.
13
- if relative_path.start_with?('./')
14
- filename = relative_path.delete_prefix! './'
15
- end
15
+ # Handle absolute path.
16
+ if relative_path.start_with?('/') && File.exist?(relative_path)
17
+ absolute_path = relative_path.split('/')
18
+ file_name = absolute_path.pop
19
+ # Handle relative path.
20
+ else
21
+ # Get directory of the file that called this file.
22
+ if current_directory.nil?
23
+ absolute_path = caller_locations.first.absolute_path.split('/')
24
+ absolute_path.pop
25
+ else
26
+ absolute_path = current_directory.split('/')
27
+ end
16
28
 
17
- # When relative path is parent directory.
18
- while relative_path.start_with?('../')
19
- relative_path.delete_prefix! '../'
20
- absolute_path.pop
29
+ # When path is current directory.
30
+ if relative_path.start_with?('./')
31
+ relative_path.delete_prefix! './'
32
+ end
33
+
34
+ # When path is parent directory.
35
+ while relative_path.start_with?('../')
36
+ relative_path.delete_prefix! '../'
37
+ absolute_path.pop
38
+ end
39
+
40
+ # When path contains child directories.
41
+ if relative_path.split('/').count > 1
42
+ # Add child directories to absolute path and remove from relative path.
43
+ child_path = relative_path.split('/')
44
+ relative_path = child_path.pop
45
+ child_path.each do |dir|
46
+ absolute_path << dir
47
+ end
48
+ end
49
+
50
+ file_name = relative_path
21
51
  end
22
52
 
23
53
  # Append default extension.
24
- unless filename.end_with? '.rb'
25
- filename << '.rb'
54
+ unless file_name.end_with? '.rb'
55
+ file_name << '.rb'
26
56
  end
27
57
 
28
- filepath = File.join(absolute_path.join('/'), relative_path)
58
+ file_path = File.join(absolute_path.join('/'), file_name)
59
+
60
+ unless @@lit_processed_paths.include? file_path
61
+ @@lit_processed_paths.add file_path
62
+
63
+ new_lines = ''
64
+ File.foreach(file_path) do |line|
65
+
66
+ # Pass current directory into the next file's requires.
67
+ if line.strip.start_with? 'require_relative '
68
+ line = line.strip + ", '#{absolute_path.join('/')}'\n"
69
+ new_lines << line
70
+ else
71
+ new_lines << line
72
+ end
29
73
 
30
- # Add pry binding beneath each lit message.
31
- new_lines = ''
32
- File.foreach(filepath) do |line|
33
- new_lines << line
34
- if line.strip.start_with? 'lit "'
35
- new_lines << "binding.pry if LitCLI.is_prying?\n"
36
- new_lines << "@@is_prying = false\n"
74
+ # Add pry binding beneath each lit message.
75
+ if line.strip.start_with? 'lit "'
76
+ new_lines << "binding.pry if LitCLI.is_prying?\n"
77
+ new_lines << "@@is_prying = false\n"
78
+ end
37
79
  end
38
- end
39
80
 
40
- eval(new_lines)
81
+ eval(new_lines, get_binding(__dir__ = absolute_path), file_path)
82
+ return true
83
+ # Path has already been required.
84
+ else
85
+ return false
86
+ end
41
87
  end
42
88
 
43
- # TODO: Investigate RubyGems `require` before overriding.
44
- # SEE: https://github.com/ruby/ruby/blob/v2_6_3/lib/rubygems/core_ext/kernel_require.rb
45
- #
46
- # def require path
47
- # absolute_path = File.join(Dir.pwd, path)
48
- # #p "requiring #{absolute_path}"
49
- # #p __dir__
50
- # #p File.dirname(File.realpath(__FILE__))
51
- # #p File.realpath(__FILE__)
52
- #
53
- # # Split client-side and server-side code.
54
- # new_lines = []
55
- # binding_line = "binding.pry if LitCLI.is_prying?"
56
- #
57
- # # Add pry binding beneath each lit message.
58
- # p path
59
- # File.foreach(path) do |line|
60
- # new_lines << line
61
- # if line.strip.start_with? 'lit "'
62
- # new_lines << binding_line
63
- # end
64
- # end
65
- #
66
- # eval(new_lines.join)
67
- # end
68
-
89
+ def get_binding(__dir__)
90
+ # Don't go to this binding when Pry session activated.
91
+ # The variables have already been evaluated by eval(). NEEDS CONFIRMATION.
92
+ # Setting file_path in eval() negates this fix but will keep just in case.
93
+ return binding unless LitCLI.is_prying?
94
+ end
69
95
  end
70
96
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lit-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maedi Prichard