lit-cli 0.5.0 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/bin/lit +1 -1
  3. data/lib/config.rb +10 -7
  4. data/lib/lit_cli.rb +13 -4
  5. data/lib/lit_pry.rb +88 -49
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d016a1786059f76f691d0dd55ab4a8d2e408f4b2ee5bca3d8e42ea29012d379
4
- data.tar.gz: 5f0756f25977560051e7b07b86ae795584e954fa14eeb4533f56505c60d9cdfd
3
+ metadata.gz: 6f467ef2808f341c61ebfa6ae5cbe7cbe354c4e9d2068aa8de96ee0e4b69175e
4
+ data.tar.gz: 36cbff3ecfa9c4585e6a1fed552bbdc35f2ef7d8ef51890439dd333049cb9008
5
5
  SHA512:
6
- metadata.gz: b902f2d26e1b868be3026783a2f99e10a34ca1be0851cd73b5c16c2a4ef23fad146b5f9f51ddaca41975b249833c6f382cd47468f21ef6c2ecfa1638a9a2382e
7
- data.tar.gz: 01c08ebe1937ed4d31240aed5bcda06c4d5f85b9d6c28c23ca21b939e547e6267fc7e6248d7f3d14972bd5e9b1ea27dc74df5c38fd3d39f2aaa0a09e5340fef2
6
+ metadata.gz: caa0776bab81bc74a9c166e966f4fe12eabcd291e7147b036a6893520d083a0b1e2addde2ac76d3ff965f6cca629b6b2372ee154b47861c08cacf714bdae512d
7
+ data.tar.gz: 9204b7bdec4d2365fc5b17d513df0cbea56d4051a59baa8e3182b22b0e07d7c7658b45cf18ed0d12b2cf1bfab207ecc6d8176a6a4d8ab190447df979cc759ab7
data/bin/lit CHANGED
@@ -8,7 +8,7 @@
8
8
  # lit rails server
9
9
  ################################################################################
10
10
 
11
- ENV['LIT_ENABLED'] = 'true'
11
+ ENV['LIT_ENABLED'] = Time.now.to_i.to_s
12
12
 
13
13
  # Get flags from arguments.
14
14
  args = []
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
@@ -70,7 +70,10 @@ module LitCLI
70
70
 
71
71
  # Override config from command line.
72
72
  def cli_configure()
73
- @enabled = true if ENV['LIT_ENABLED'] == 'true'
73
+
74
+ # Enable lit via the command line.
75
+ @enabled = true if ENV['LIT_ENABLED'] == Time.now.to_i.to_s
76
+ return unless @enabled
74
77
 
75
78
  # Convert flag string to hash.
76
79
  flags = {}
data/lib/lit_cli.rb CHANGED
@@ -8,18 +8,22 @@ module LitCLI
8
8
  @@config = Config.new
9
9
  @@is_prying = false
10
10
 
11
- def lit(message, status = :info, type = nil)
11
+ def lit(message, status = :info, type = nil, context = nil)
12
12
  if @@config.enabled
13
13
  return if LitCLI.filter_status? status
14
14
  return if LitCLI.filter_type? type
15
- LitCLI.render(message, status, type)
15
+
16
+ LitCLI.render(message, status, type, context)
17
+
16
18
  LitCLI.step()
19
+ yield if block_given?
20
+
17
21
  LitCLI.delay()
18
22
  end
19
23
  end
20
24
  alias 🔥 lit
21
25
 
22
- def self.render(message, status, type)
26
+ def self.render(message, status, type, context)
23
27
  text = "🔥"
24
28
 
25
29
  # Time.
@@ -40,6 +44,9 @@ module LitCLI
40
44
  end
41
45
  end
42
46
 
47
+ # Context.
48
+ text << LitCLI.format(" #{context}", styles: [:bold, :dim])
49
+
43
50
  # Message.
44
51
  text << " #{message}"
45
52
 
@@ -91,6 +98,8 @@ module LitCLI
91
98
  text = text.upcase
92
99
  when :downcase
93
100
  text = text.downcase
101
+ when :capitalize
102
+ text = text.capitalize
94
103
  end
95
104
  end
96
105
  # Then apply styling.
@@ -140,7 +149,7 @@ module LitCLI
140
149
  def self.configure()
141
150
  yield(@@config)
142
151
 
143
- # Override config from command line.
152
+ # Override config from flags on command line.
144
153
  @@config.cli_configure()
145
154
  end
146
155
 
data/lib/lit_pry.rb CHANGED
@@ -1,70 +1,109 @@
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
28
+
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
16
49
 
17
- # When relative path is parent directory.
18
- while relative_path.start_with?('../')
19
- relative_path.delete_prefix! '../'
20
- absolute_path.pop
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)
29
59
 
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"
60
+ unless @@lit_processed_paths.include? file_path
61
+ @@lit_processed_paths.add file_path
62
+
63
+ new_lines = ''
64
+ line_count = 0
65
+ new_lines_count = 0
66
+
67
+ File.foreach(file_path) do |line|
68
+ line_count = line_count + 1
69
+
70
+ # Pass current directory into the next file's requires.
71
+ if line.strip.start_with? 'require_relative '
72
+ line = line.strip + ", '#{absolute_path.join('/')}'\n"
73
+ new_lines << line
74
+ # Add pry binding on each lit method.
75
+ elsif lit_line = Kernel.add_lit_binding(line)
76
+ new_lines << lit_line
77
+ else
78
+ new_lines << line
79
+ end
37
80
  end
81
+
82
+ eval(new_lines, get_binding(__dir__ = absolute_path), file_path)
83
+
84
+ return true
85
+ # Path has already been required.
86
+ else
87
+ return false
38
88
  end
89
+ end
39
90
 
40
- eval(new_lines)
91
+ def get_binding(__dir__)
92
+ # Don't go to this binding when Pry session activated.
93
+ # The variables have already been evaluated by eval(). NEEDS CONFIRMATION.
94
+ # Setting file_path in eval() negates this fix but will keep just in case.
95
+ return binding unless LitCLI.is_prying?
41
96
  end
42
97
 
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
98
+ def self.add_lit_binding(line)
99
+ ['lit ', 'lit(', '🔥 ', '🔥(', '🔥'].each do |needle|
100
+ if line.strip.start_with? needle
101
+ args = line.strip.delete_prefix(needle).delete_suffix(")").chomp
102
+ return "lit(#{args}) { binding.pry if LitCLI.is_prying?; @@is_prying = false } \n"
103
+ end
104
+ end
68
105
 
106
+ false
107
+ end
69
108
  end
70
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lit-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maedi Prichard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-08 00:00:00.000000000 Z
11
+ date: 2021-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel