console1984 0.1.10 → 0.1.14
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edce6968a693f97b73d1e0c54ae8d0e83b659a71ef229bc8486c46f456f65783
|
4
|
+
data.tar.gz: 8705e765cf98e7ec0ee828c5134694670a71779ff7e065ffed27e2a5e7b2dfc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51a530838a4a651ffef1df68cc8f724f5e30998c90b44fd34ec1dd63a187b5344b662fffe3abd077a89586eab503f07841dd780ee1739320aedbf83add9b6455
|
7
|
+
data.tar.gz: a24336a400da036dec22b6791234f83d09b4c313e61c37f80c6cc594b3f15ef8fe42313a6c1e2d092da0623b430d93be458513775fa88012fa8f63d8e1074362
|
data/config/protections.yml
CHANGED
@@ -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
|
@@ -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: :
|
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
|
17
|
-
@
|
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,16 @@ 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"
|
48
|
+
|
49
|
+
# This solves a weird class loading error where ActiveRecord dosn't resolve +Relation+ properly.
|
50
|
+
# See https://github.com/basecamp/console1984/issues/29
|
51
|
+
#
|
52
|
+
# TODO: This is a temporary fix. Need to figure out why/when this happens.
|
53
|
+
require "active_record/relation"
|
44
54
|
end
|
45
55
|
|
46
56
|
def start_session
|
data/lib/console1984/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.14
|
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-
|
11
|
+
date: 2021-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -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
|