Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add Maglev.[] and Maglev.[]= as accessors for root #337

Merged
merged 3 commits into from

2 participants

@johnnyt
Owner

These would also be nice in Ruby land - any objections?

@jc00ke
Collaborator

:+1:

Should we be adding specs for stuff like this?

@johnnyt
Owner

Fantastic point - I won't merge until they have specs.

I'm also working on updating some of the docs.

@johnnyt johnnyt merged commit 7bc05ec into master

1 check passed

Details default The Travis CI build passed
@johnnyt johnnyt deleted the johnnyt/hash-access branch
@jc00ke
Collaborator

:+1: Yeah, that's much better :wink:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 36 additions and 1 deletion.
  1. +27 −0 spec/maglev/maglev_spec.rb
  2. +9 −1 src/kernel/bootstrap/Maglev.rb
View
27 spec/maglev/maglev_spec.rb
@@ -0,0 +1,27 @@
+require File.expand_path '../../spec_helper', __FILE__
+
+describe 'Maglev' do
+
+ describe '#root' do
+ it 'references Maglev::PERSISTENT_ROOT' do
+ Maglev.root.should == Maglev::PERSISTENT_ROOT
+ end
+ end
+
+ describe '#[]' do
+ it 'references Maglev::PERSISTENT_ROOT' do
+ message = 'hello world'
+ Maglev::PERSISTENT_ROOT[:message] = message
+ Maglev[:message].should == message
+ end
+ end
+
+ describe '#[]=' do
+ it 'updates Maglev::PERSISTENT_ROOT' do
+ message = 'hello world'
+ Maglev[:message] = message
+ Maglev::PERSISTENT_ROOT[:message].should == message
+ end
+ end
+
+end
View
10 src/kernel/bootstrap/Maglev.rb
@@ -50,7 +50,15 @@ module Maglev
def root
PERSISTENT_ROOT
end
- module_function :root
+
+ def [](key)
+ root[key]
+ end
+
+ def []=(key, value)
+ root[key] = value
+ end
+ module_function :root, :[], :[]=
# Executes the block with the current thread in transient mode, which
# affects the following operations:
Something went wrong with that request. Please try again.