lowkey 0.4.1 → 0.4.2
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 +4 -4
- data/lib/factories/source_factory.rb +6 -5
- data/lib/interfaces/proxy.rb +1 -1
- data/lib/models/source.rb +16 -4
- data/lib/proxies/class_proxy.rb +2 -1
- data/lib/queries/query.rb +5 -0
- data/lib/version.rb +1 -1
- data/lib/visitors/class_visitor.rb +1 -1
- data/lib/visitors/method_call_visitor.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c3c9495f9a78f72d1c42103c7feca2dd8bc07aee9621658e20849f9aca22952
|
|
4
|
+
data.tar.gz: 3a9f9940d723fadc08d8f6ac552eb79f2cdfc56b4b01316498b18fd327b5ebed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d1e42a9e1d4dbdd21dcf869d6c2862724b5e609c1e8f5c8716ae530edaca518f655de6d04aff0b9686746a7cd06e00665a243bd60d3a5f8bdc7a3b57435f8912
|
|
7
|
+
data.tar.gz: d0ccec589e58a7a1f379e683689f52fbc2cd8b1ea71dce3bb809a3f3267ae4427f1f83885d08231fadc56b567ecefb9820a5a1438ca797510a35fd5549d282c6
|
|
@@ -6,13 +6,13 @@ module Lowkey
|
|
|
6
6
|
class SourceFactory
|
|
7
7
|
class << self
|
|
8
8
|
def file_source(root_node:, file_path:)
|
|
9
|
-
end_line = root_node.respond_to?(:end_line) ? root_node.end_line : nil
|
|
9
|
+
end_line = root_node.respond_to?(:end_line) ? root_node.end_line : nil # TODO: Get file line count.
|
|
10
10
|
|
|
11
|
-
Source.new(file_path:, scope: 'file', lines: root_node.script_lines, start_line:
|
|
11
|
+
Source.new(file_path:, scope: 'file', lines: root_node.script_lines, start_line: 1, end_line:)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def module_source(node:, namespace:, file_path:, lines:)
|
|
15
|
-
start_line = node.respond_to?(:class_keyword_loc) ? node.class_keyword_loc.start_line :
|
|
15
|
+
start_line = node.respond_to?(:class_keyword_loc) ? node.class_keyword_loc.start_line : 1
|
|
16
16
|
end_line = node.respond_to?(:end_keyword_loc) ? node.end_keyword_loc.end_line : start_line
|
|
17
17
|
end_line = node.end_line if namespace == 'Object'
|
|
18
18
|
scope = node.respond_to?(:name) ? node.name : 'Object'
|
|
@@ -21,7 +21,7 @@ module Lowkey
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def class_source(node:, file_path:, lines:)
|
|
24
|
-
start_line = node.respond_to?(:class_keyword_loc) ? node.class_keyword_loc.start_line :
|
|
24
|
+
start_line = node.respond_to?(:class_keyword_loc) ? node.class_keyword_loc.start_line : 1
|
|
25
25
|
end_line = node.respond_to?(:end_keyword_loc) ? node.end_keyword_loc.end_line : start_line
|
|
26
26
|
|
|
27
27
|
Source.new(file_path:, scope: node.name, lines:, start_line:, end_line:)
|
|
@@ -31,7 +31,8 @@ module Lowkey
|
|
|
31
31
|
scope = method_node.name
|
|
32
32
|
start_line = method_node.start_line
|
|
33
33
|
end_line = method_node.end_line
|
|
34
|
-
|
|
34
|
+
# TODO: Brittle conditional. What we really want to identify is if the method/rest of file was able to be parsed into an AST.
|
|
35
|
+
end_line = end_line_from_indent(method_node:, lines:) if end_line >= lines.count
|
|
35
36
|
|
|
36
37
|
Source.new(file_path:, scope:, lines:, start_line:, end_line:)
|
|
37
38
|
end
|
data/lib/interfaces/proxy.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Lowkey
|
|
|
10
10
|
|
|
11
11
|
attr_reader :name
|
|
12
12
|
|
|
13
|
-
def_delegators :@source, :file_path, :lines, :start_line, :end_line, :scope
|
|
13
|
+
def_delegators :@source, :file_path, :lines, :lines=, :start_line, :end_line, :scope
|
|
14
14
|
def_delegators :@source, :wrap, :export
|
|
15
15
|
|
|
16
16
|
def initialize(name:, source:)
|
data/lib/models/source.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Lowkey
|
|
4
|
+
class WriteError < StandardError; end
|
|
5
|
+
|
|
4
6
|
class Source
|
|
5
|
-
attr_reader :file_path, :scope
|
|
6
|
-
attr_accessor :
|
|
7
|
+
attr_reader :file_path, :scope, :lines
|
|
8
|
+
attr_accessor :start_line, :end_line
|
|
7
9
|
|
|
8
10
|
def initialize(file_path:, scope:, lines:, start_line:, end_line: nil)
|
|
9
11
|
@file_path = file_path
|
|
@@ -14,16 +16,26 @@ module Lowkey
|
|
|
14
16
|
@lines = lines
|
|
15
17
|
end
|
|
16
18
|
|
|
19
|
+
def lines=(new_lines)
|
|
20
|
+
raise WriteError, "More new lines than old lines, won't fit" if new_lines.count > lines.count
|
|
21
|
+
|
|
22
|
+
indent = lines[start_index][/^\s+/]
|
|
23
|
+
|
|
24
|
+
[start_index..end_index].each do |line_index|
|
|
25
|
+
lines[line_index] = indent + new_lines.pop.to_s || ''
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
17
29
|
def wrap(prefix:, suffix:)
|
|
18
30
|
start_line = lines[start_index]
|
|
19
31
|
indent = start_line[/^\s+/]
|
|
20
|
-
lines[start_index] = indent + prefix.to_s + start_line.lstrip
|
|
21
32
|
|
|
33
|
+
lines[start_index] = indent + prefix.to_s + start_line.lstrip
|
|
22
34
|
lines[end_index] = lines[end_index] + suffix.to_s
|
|
23
35
|
end
|
|
24
36
|
|
|
25
37
|
def export
|
|
26
|
-
lines.join
|
|
38
|
+
lines[start_index..end_index].join
|
|
27
39
|
end
|
|
28
40
|
|
|
29
41
|
private
|
data/lib/proxies/class_proxy.rb
CHANGED
|
@@ -4,12 +4,13 @@ require_relative 'module_proxy'
|
|
|
4
4
|
|
|
5
5
|
module Lowkey
|
|
6
6
|
class ClassProxy < ModuleProxy
|
|
7
|
-
attr_accessor :instance_methods
|
|
7
|
+
attr_accessor :instance_methods, :class_binding
|
|
8
8
|
|
|
9
9
|
def initialize(node:, name:, namespace:, source:)
|
|
10
10
|
super(node:, name:, namespace:, source:)
|
|
11
11
|
|
|
12
12
|
@instance_methods = {}
|
|
13
|
+
@class_binding = nil
|
|
13
14
|
end
|
|
14
15
|
end
|
|
15
16
|
end
|
data/lib/queries/query.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'prism'
|
|
4
|
+
|
|
3
5
|
module Lowkey
|
|
4
6
|
module Query
|
|
5
7
|
# TODO: Make name a keypath.
|
|
@@ -10,6 +12,9 @@ module Lowkey
|
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def namespace(node:, parent_map:, namespace: [])
|
|
15
|
+
# When inside RBX, Prism thinks we're defining a class because of "<".
|
|
16
|
+
return nil if node.respond_to?(:constant_path) && node.constant_path.is_a?(Prism::MissingNode)
|
|
17
|
+
|
|
13
18
|
if parent_map[node].nil?
|
|
14
19
|
namespace << 'Object' if namespace.empty?
|
|
15
20
|
return namespace.reverse.join('::')
|
data/lib/version.rb
CHANGED
|
@@ -13,7 +13,7 @@ module Lowkey
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def visit(node)
|
|
16
|
-
namespace = namespace(node:, parent_map:)
|
|
16
|
+
namespace = namespace(node:, parent_map:) || return
|
|
17
17
|
class_proxy = ProxyFactory.class_proxy(node:, namespace:, file_path:, lines:)
|
|
18
18
|
@file_proxy.upsert_definition(module_proxy: class_proxy)
|
|
19
19
|
end
|