Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initialized event #296

Merged
merged 1 commit into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/iruby/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class Kernel
RED = "\e[31m"
RESET = "\e[0m"

class<< self
@events = EventManager.new([:initialized])

class << self
attr_reader :events
attr_accessor :instance
end

Expand Down Expand Up @@ -33,6 +36,8 @@ def initialize(config_file, session_adapter_name=nil)
@execution_count = 0
@backend = create_backend
@running = true

self.class.events.trigger(:initialized, self)
end

attr_reader :events
Expand Down
19 changes: 19 additions & 0 deletions test/iruby/kernel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ def setup
@kernel = IRuby::Kernel.instance
end

sub_test_case("iruby_initialized event") do
def setup
super
@initialized_kernel = nil
@callback = IRuby::Kernel.events.register(:initialized) do |kernel|
@initialized_kernel = kernel
end
end

def teardown
IRuby::Kernel.events.unregister(:initialized, @callback)
end

def test_iruby_initialized_event
with_session_adapter("test")
assert_same(IRuby::Kernel.instance, @initialized_kernel)
end
end

def test_execute_request
obj = Object.new

Expand Down