Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 3 commits into from

2 participants

JohnnyT Jesse Cooke
JohnnyT
Owner

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

Jesse Cooke
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 from
JohnnyT johnnyt deleted the branch
Jesse Cooke
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
27 spec/maglev/maglev_spec.rb
View
@@ -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
10 src/kernel/bootstrap/Maglev.rb
View
@@ -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.