console1984 0.1.10 → 0.1.11

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
2
  SHA256:
3
- metadata.gz: 6d40ddccd6e06beaf5f506991d87a1b60d20246d6320e92a5dda0dceef86c746
4
- data.tar.gz: 03cf91cc60cd5764665042e918c5241464ae4b2ab923dad19e7ccac28ae0954f
3
+ metadata.gz: 472b88a03c5befd81877d190baa41cd0cd4d4a985fff797ddc447e729e6fa56a
4
+ data.tar.gz: 9c791955b0caf6d49fd655905a9d37a231bb7ee668f5b2a1dd85e4ebd14efdaa
5
5
  SHA512:
6
- metadata.gz: db4dab2e225fb0565cf7654ac9030aecba5372f404e813633e088b615ad834c1283319456bb0c69b5c5526e5a2f8387c9151bb1f59ba20889d40993b3db29e9e
7
- data.tar.gz: 921511573b0f9ad7c8d9019dbe2b83db1d5f054740508e33c48aea31de441a580a7d4ddecc75d9f722388028b08fae46fce5c1d7503a688598bf8b72d0121c14
6
+ metadata.gz: 8300ef44660e9b9933ae68ebfc4b26f0e57849c716b1339817e00332407a0696df4e46599f056be186171cc884bf8c8fb4c1eba688aecf7702c04d1ad0ad69a9
7
+ data.tar.gz: b7a073d5bfc4f648fc10f5bb331320ae0b84a7afa3e1108df9005faedc2f51a338fd9b3d659ecf5fe0744bee6067e444e75dd67a12c53647d6c079fdb554e5fa
@@ -6,85 +6,19 @@ class Console1984::CommandValidator::ParsedCommand
6
6
 
7
7
  attr_reader :raw_command
8
8
 
9
- delegate :declared_classes_or_modules, :constants, :constant_assignments, to: :processed_ast
9
+ delegate :declared_classes_or_modules, :constants, :constant_assignments, to: :command_parser
10
10
 
11
11
  def initialize(raw_command)
12
12
  @raw_command = Array(raw_command).join("\n")
13
13
  end
14
14
 
15
15
  private
16
- def processed_ast
17
- @processed_ast ||= CommandProcessor.new.tap do |processor|
16
+ def command_parser
17
+ @command_parser ||= Console1984::CommandValidator::CommandParser.new.tap do |processor|
18
18
  ast = Parser::CurrentRuby.parse(raw_command)
19
19
  processor.process(ast)
20
20
  rescue Parser::SyntaxError
21
21
  # Fail open with syntax errors
22
22
  end
23
23
  end
24
-
25
- class CommandProcessor < ::Parser::AST::Processor
26
- include AST::Processor::Mixin
27
- include Console1984::Freezeable
28
-
29
- def initialize
30
- @constants = []
31
- @declared_classes_or_modules = []
32
- @constant_assignments = []
33
- end
34
-
35
- # We define accessors to define lists without duplicates. We are not using a +SortedSet+ because we want
36
- # to mutate strings in the list while the processing is happening. And we don't use metapgroamming to define the
37
- # accessors to prevent having problems with freezable and its instance_variable* protection.
38
-
39
- def constants
40
- @constants.uniq
41
- end
42
-
43
- def declared_classes_or_modules
44
- @declared_classes_or_modules.uniq
45
- end
46
-
47
- def constant_assignments
48
- @constant_assignments.uniq
49
- end
50
-
51
- def on_class(node)
52
- super
53
- const_declaration, _, _ = *node
54
- constant = extract_constants(const_declaration).first
55
- @declared_classes_or_modules << constant if constant.present?
56
- end
57
-
58
- alias_method :on_module, :on_class
59
-
60
- def on_const(node)
61
- super
62
- name, const_name = *node
63
- const_name = const_name.to_s
64
- last_constant = @constants.last
65
-
66
- if name.nil? || (name && name.type == :cbase) # cbase = leading ::
67
- if last_constant&.end_with?("::")
68
- last_constant << const_name
69
- else
70
- @constants << const_name
71
- end
72
- elsif last_constant
73
- last_constant << "::#{const_name}"
74
- end
75
- end
76
-
77
- def on_casgn(node)
78
- super
79
- scope_node, name, value_node = *node
80
- @constant_assignments.push(*extract_constants(value_node))
81
- end
82
-
83
- private
84
- def extract_constants(node)
85
- self.class.new.tap do |processor|
86
- processor.process(node)
87
- end.constants
88
- end
89
- end
90
24
  end
@@ -41,6 +41,10 @@ class Console1984::Supervisor
41
41
  require 'parser/current'
42
42
  end
43
43
  require 'colorized_string'
44
+
45
+ # Explicit lazy loading because it depends on +parser+, which we want to only load
46
+ # in console sessions.
47
+ require_relative "./command_validator/.command_parser"
44
48
  end
45
49
 
46
50
  def start_session
@@ -1,3 +1,3 @@
1
1
  module Console1984
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console1984
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Manrubia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-08 00:00:00.000000000 Z
11
+ date: 2021-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize