Skip to content
Browse files

RootScope -> NullScope

  • Loading branch information...
1 parent d6c55b4 commit d4540f5749be73e9c0ffbb1fbd0b9e88c56a55fb @blambeau committed Jun 13, 2012
View
6 CHANGELOG.md
@@ -1,3 +1,9 @@
+# 2.1.0 / FIX ME
+
+## Changes to private APIs
+
+* RootScope as been renamed to NullScope, Scope.root to Scope.null accordingly
+
# 2.0.1 / 2012-06-12
* Fix support for 1.8.7 and jruby (undefined method `ord' for String)
View
2 lib/wlang/dialect.rb
@@ -158,7 +158,7 @@ def render(fn, scope = nil, buffer = "")
# Returns the current rendering scope.
def scope
- @scope ||= Scope.root
+ @scope ||= Scope.null
end
# Yields the block with a scope branched with a sub-scope `x`.
View
12 lib/wlang/scope.rb
@@ -8,13 +8,13 @@ def initialize(subject, parent)
@subject, @parent = subject, parent
end
- def self.root
- @root ||= RootScope.new
+ def self.null
+ @null ||= NullScope.new
end
def self.coerce(arg, parent = nil)
return arg if Scope===arg && parent.nil?
- parent ||= root
+ parent ||= null
clazz = case arg
when Binding
BindingScope
@@ -29,7 +29,9 @@ def self.coerce(arg, parent = nil)
end
def self.chain(scopes)
- scopes.compact.inject(nil){|parent,child| Scope.coerce(child, parent)} || root
+ scopes.compact.inject(nil){|parent,child|
+ Scope.coerce(child, parent)
+ } || null
end
def push(x)
@@ -59,7 +61,7 @@ def evaluate(expr, *default)
end # class Scope
end # module WLang
-require 'wlang/scope/root_scope'
+require 'wlang/scope/null_scope'
require 'wlang/scope/proxy_scope'
require 'wlang/scope/object_scope'
require 'wlang/scope/binding_scope'
View
6 lib/wlang/scope/root_scope.rb → lib/wlang/scope/null_scope.rb
@@ -1,6 +1,6 @@
module WLang
class Scope
- class RootScope < Scope
+ class NullScope < Scope
def initialize
super(nil,nil)
@@ -15,10 +15,10 @@ def fetch(key)
end
def inspect
- "RootScope"
+ "NullScope"
end
alias :to_s :inspect
- end # class RootScope
+ end # class NullScope
end # class Scope
end # module WLang
View
10 spec/unit/scope/test_chain.rb
@@ -1,28 +1,28 @@
module WLang
describe Scope, '.chain' do
- it 'returns Scope.root on empty chain' do
- Scope.chain([]).should eq(Scope.root)
+ it 'returns Scope.null on empty chain' do
+ Scope.chain([]).should eq(Scope.null)
end
it 'returns a single scope on singleton' do
s = Scope.chain([{:who => "World"}])
s.should be_a(Scope::ObjectScope)
- s.parent.should eq(Scope.root)
+ s.parent.should eq(Scope.null)
end
it 'uses the last scope as most specific' do
s = Scope.chain([{:who => "World"}, lambda{}])
s.should be_a(Scope::ProcScope)
s.parent.should be_a(Scope::ObjectScope)
- s.parent.parent.should eq(Scope.root)
+ s.parent.parent.should eq(Scope.null)
end
it 'strips nils' do
s = Scope.chain([nil, {:who => "World"}, nil, lambda{}, nil])
s.should be_a(Scope::ProcScope)
s.parent.should be_a(Scope::ObjectScope)
- s.parent.parent.should eq(Scope.root)
+ s.parent.parent.should eq(Scope.null)
end
end
View
4 spec/unit/scope/test_coerce.rb
@@ -19,14 +19,14 @@ module WLang
end
it 'returns the Scope if nothing has to be done' do
- Scope.coerce(Scope.root).should eq(Scope.root)
+ Scope.coerce(Scope.null).should eq(Scope.null)
s = Scope.coerce({})
Scope.coerce(s).should eq(s)
end
it 'builds ProxyScope on Scopes' do
s = Scope.coerce({})
- Scope.coerce(s, Scope.root).should be_a(Scope::ProxyScope)
+ Scope.coerce(s, Scope.null).should be_a(Scope::ProxyScope)
end
end # describe Scope
View
4 spec/unit/scope/test_root_scope.rb → spec/unit/scope/test_null_scope.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
module WLang
class Scope
- describe RootScope do
+ describe NullScope do
- let(:scope){ RootScope.new }
+ let(:scope){ NullScope.new }
it 'throws on fetch' do
lambda{ scope.fetch(:who) }.should throw_symbol(:fail)
View
2 spec/unit/scope/test_proxy_scope.rb
@@ -9,7 +9,7 @@ class Scope
end
it 'delegates fetch to its parent when not found' do
- proxy = Scope.coerce(Scope.root, Scope.coerce(:who => "World"))
+ proxy = Scope.coerce(Scope.null, Scope.coerce(:who => "World"))
proxy.fetch(:who).should eq("World")
end

0 comments on commit d4540f5

Please sign in to comment.
Something went wrong with that request. Please try again.