forked from gsamokovarov/web-console
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from sh19910711/patch/0037/auto-complete
Add auto-completion feature
- Loading branch information
Showing
18 changed files
with
528 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,4 @@ matrix: | |
- env: TEST_SUITE=test:templates | ||
include: | ||
- env: TEST_SUITE=test:templates | ||
rvm: 2.2 | ||
rvm: 2.2.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module WebConsole | ||
# A context lets you get object names related to the current session binding. | ||
class Context | ||
def initialize(binding) | ||
@binding = binding | ||
end | ||
|
||
# Extracts entire objects which can be called by the current session unless the objpath is present. | ||
# Otherwise, it extracts methods and constants of the object specified by the objpath. | ||
def extract(objpath) | ||
if objpath.present? | ||
local(objpath) | ||
else | ||
global | ||
end | ||
end | ||
|
||
private | ||
|
||
GLOBAL_OBJECTS = [ | ||
'global_variables', | ||
'local_variables', | ||
'instance_variables', | ||
'instance_methods', | ||
'class_variables', | ||
'methods', | ||
'Object.constants', | ||
'Kernel.methods', | ||
] | ||
|
||
def global | ||
GLOBAL_OBJECTS.map { |cmd| eval(cmd) }.flatten | ||
end | ||
|
||
def local(objpath) | ||
[ | ||
eval("#{objpath}.methods").map { |m| "#{objpath}.#{m}" }, | ||
eval("#{objpath}.constants").map { |c| "#{objpath}::#{c}" }, | ||
].flatten | ||
end | ||
|
||
def eval(cmd) | ||
@binding.eval(cmd) rescue [] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.