console1984 0.1.11 → 0.1.12

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: 472b88a03c5befd81877d190baa41cd0cd4d4a985fff797ddc447e729e6fa56a
4
- data.tar.gz: 9c791955b0caf6d49fd655905a9d37a231bb7ee668f5b2a1dd85e4ebd14efdaa
3
+ metadata.gz: a3bfdacf3954fbc30c23046c89f7951d061c419533685fb5ecc2db6a6cf41a1d
4
+ data.tar.gz: 0b26c9effb7ffdd1df5ca51c344c53c3d9260bef1b02c4c2d9e6c8949dceb032
5
5
  SHA512:
6
- metadata.gz: 8300ef44660e9b9933ae68ebfc4b26f0e57849c716b1339817e00332407a0696df4e46599f056be186171cc884bf8c8fb4c1eba688aecf7702c04d1ad0ad69a9
7
- data.tar.gz: b7a073d5bfc4f648fc10f5bb331320ae0b84a7afa3e1108df9005faedc2f51a338fd9b3d659ecf5fe0744bee6067e444e75dd67a12c53647d6c079fdb554e5fa
6
+ metadata.gz: b24bf1fbfc353fdd8b5ac2194f4f30588281269748ea192def291cdedc19697b1bd75bff71baec0761e45ff08ec78aca78ff41d0b78c8ca6ae1cea4bdb43512e
7
+ data.tar.gz: 43628c0bd4f76662b65f1c343885618a4c54e2b8b40d536720f8c3eecd696ae51c03c78329810387598e68042622b6c6c15f6b015caf3b93d6fb3779bf349f95
@@ -0,0 +1,69 @@
1
+ # Naming class with dot so that it doesn't get loaded eagerly by Zeitwork. We want to load
2
+ # only when a console session is started, when +parser+ is loaded.
3
+ #
4
+ # See +Console1984::Supervisor#require_dependencies+
5
+ class Console1984::CommandValidator::CommandParser < ::Parser::AST::Processor
6
+ include AST::Processor::Mixin
7
+ include Console1984::Freezeable
8
+
9
+ def initialize
10
+ @constants = []
11
+ @declared_classes_or_modules = []
12
+ @constant_assignments = []
13
+ end
14
+
15
+ # We define accessors to define lists without duplicates. We are not using a +SortedSet+ because we want
16
+ # to mutate strings in the list while the processing is happening. And we don't use metapgroamming to define the
17
+ # accessors to prevent having problems with freezable and its instance_variable* protection.
18
+
19
+ def constants
20
+ @constants.uniq
21
+ end
22
+
23
+ def declared_classes_or_modules
24
+ @declared_classes_or_modules.uniq
25
+ end
26
+
27
+ def constant_assignments
28
+ @constant_assignments.uniq
29
+ end
30
+
31
+ def on_class(node)
32
+ super
33
+ const_declaration, _, _ = *node
34
+ constant = extract_constants(const_declaration).first
35
+ @declared_classes_or_modules << constant if constant.present?
36
+ end
37
+
38
+ alias_method :on_module, :on_class
39
+
40
+ def on_const(node)
41
+ super
42
+ name, const_name = *node
43
+ const_name = const_name.to_s
44
+ last_constant = @constants.last
45
+
46
+ if name.nil? || (name && name.type == :cbase) # cbase = leading ::
47
+ if last_constant&.end_with?("::")
48
+ last_constant << const_name
49
+ else
50
+ @constants << const_name
51
+ end
52
+ elsif last_constant
53
+ last_constant << "::#{const_name}"
54
+ end
55
+ end
56
+
57
+ def on_casgn(node)
58
+ super
59
+ scope_node, name, value_node = *node
60
+ @constant_assignments.push(*extract_constants(value_node))
61
+ end
62
+
63
+ private
64
+ def extract_constants(node)
65
+ self.class.new.tap do |processor|
66
+ processor.process(node)
67
+ end.constants
68
+ end
69
+ end
@@ -1,3 +1,3 @@
1
1
  module Console1984
2
- VERSION = '0.1.11'
2
+ VERSION = '0.1.12'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console1984
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Manrubia
@@ -200,6 +200,7 @@ files:
200
200
  - lib/console1984.rb
201
201
  - lib/console1984/command_executor.rb
202
202
  - lib/console1984/command_validator.rb
203
+ - lib/console1984/command_validator/.command_parser.rb
203
204
  - lib/console1984/command_validator/forbidden_constant_reference_validation.rb
204
205
  - lib/console1984/command_validator/forbidden_reopening_validation.rb
205
206
  - lib/console1984/command_validator/parsed_command.rb