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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2bcc0b4b60c158051ab7da59abb915078011d30cf4a231db29ddc03f87a9af4
4
- data.tar.gz: 50ed70e6d38d529f0b9d8c39cd31e3af9df2fd0f04100bf4739235d81daadb59
3
+ metadata.gz: 0c3c9495f9a78f72d1c42103c7feca2dd8bc07aee9621658e20849f9aca22952
4
+ data.tar.gz: 3a9f9940d723fadc08d8f6ac552eb79f2cdfc56b4b01316498b18fd327b5ebed
5
5
  SHA512:
6
- metadata.gz: 2585284e511997be690bffcee538d8e8e97150ce9338b803867aafc4680f1e8caa70b4d34d8d8c4952cf8ba2cd141462ae74d7b0fad0194b5e22d3cb90ed7fb5
7
- data.tar.gz: eb4a250a62dfd1cf13110095f8a4b831b9b47c282944c38f2edd642bb3f4817ddfd9fe838acd5241d0088ab93ec3d2e56c3ae6cec45dfbda2de0b84b389c019b
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: 0, end_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 : 0
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 : 0
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
- end_line = end_line_from_indent(method_node:, lines:) if end_line > lines.count
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
@@ -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 :lines, :start_line, :end_line
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lowkey
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.2'
5
5
  end
@@ -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
@@ -12,7 +12,7 @@ module Lowkey
12
12
  end
13
13
 
14
14
  def visit(node)
15
- namespace = namespace(node:, parent_map:)
15
+ namespace = namespace(node:, parent_map:) || return
16
16
  module_proxy = file_proxy[namespace]
17
17
 
18
18
  module_proxy.method_calls << node
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lowkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi