console1984 0.1.11 → 0.1.15

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: 472b88a03c5befd81877d190baa41cd0cd4d4a985fff797ddc447e729e6fa56a
4
- data.tar.gz: 9c791955b0caf6d49fd655905a9d37a231bb7ee668f5b2a1dd85e4ebd14efdaa
3
+ metadata.gz: 26a59332236edcf9b00811ef8fe7a7d6e3667763d0a58771bb09a5ef3935a64c
4
+ data.tar.gz: 03a89cc1fedb6e0837941730afb811a1e0f3f6b13393778e81993a5c577162c4
5
5
  SHA512:
6
- metadata.gz: 8300ef44660e9b9933ae68ebfc4b26f0e57849c716b1339817e00332407a0696df4e46599f056be186171cc884bf8c8fb4c1eba688aecf7702c04d1ad0ad69a9
7
- data.tar.gz: b7a073d5bfc4f648fc10f5bb331320ae0b84a7afa3e1108df9005faedc2f51a338fd9b3d659ecf5fe0744bee6067e444e75dd67a12c53647d6c079fdb554e5fa
6
+ metadata.gz: f21b2f38b9d1d1f136f7d3f83dac67cedd49fa47343e98b365c083aa58485d2a61aa0959ab8e9c6ff3086120b72bc6122e8a2c55f319419e812923e92badaf74
7
+ data.tar.gz: 50e7fdea76f8128744486dd5fddf59fd216118b7db7e51ff8c42aec0ff427fe720e94ffd308b95a6fee5c80b356dbf062e3802e1eaaac9829ac0a60e2d9c3742
@@ -5,6 +5,7 @@ validations:
5
5
  - PG
6
6
  - Mysql2
7
7
  - IRB
8
+ - Parser
8
9
  forbidden_constant_reference:
9
10
  always:
10
11
  - Console1984
@@ -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,7 +6,7 @@ module Console1984::Ext::Core::Module
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  def instance_eval(*)
9
- if Console1984.command_executor.executing_user_command?
9
+ if Console1984.command_executor.from_irb?(caller)
10
10
  raise Console1984::Errors::ForbiddenCommandAttempted
11
11
  else
12
12
  super
@@ -11,6 +11,11 @@ class Console1984::Refrigerator
11
11
  end
12
12
 
13
13
  private
14
+ def eager_load_all_classes
15
+ Rails.application.eager_load! unless Rails.application.config.eager_load
16
+ Console1984.class_loader.eager_load
17
+ end
18
+
14
19
  def freeze_internal_instances
15
20
  Console1984.config.freeze unless Console1984.config.test_mode
16
21
  end
@@ -23,9 +28,4 @@ class Console1984::Refrigerator
23
28
  # Not using a constant because we want this to run lazily (console-dependant dependencies might not be loaded).
24
29
  [Parser::CurrentRuby]
25
30
  end
26
-
27
- def eager_load_all_classes
28
- Rails.application.eager_load! unless Rails.application.config.eager_load
29
- Console1984.class_loader.eager_load
30
- end
31
31
  end
@@ -45,6 +45,12 @@ class Console1984::Supervisor
45
45
  # Explicit lazy loading because it depends on +parser+, which we want to only load
46
46
  # in console sessions.
47
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"
48
54
  end
49
55
 
50
56
  def start_session
@@ -1,3 +1,3 @@
1
1
  module Console1984
2
- VERSION = '0.1.11'
2
+ VERSION = '0.1.15'
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.11
4
+ version: 0.1.15
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-09 00:00:00.000000000 Z
11
+ date: 2021-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activeresource
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: benchmark-ips
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -200,6 +214,7 @@ files:
200
214
  - lib/console1984.rb
201
215
  - lib/console1984/command_executor.rb
202
216
  - lib/console1984/command_validator.rb
217
+ - lib/console1984/command_validator/.command_parser.rb
203
218
  - lib/console1984/command_validator/forbidden_constant_reference_validation.rb
204
219
  - lib/console1984/command_validator/forbidden_reopening_validation.rb
205
220
  - lib/console1984/command_validator/parsed_command.rb