dsl_accessor 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dsl_accessor/accessor.rb +1 -1
- data/lib/dsl_accessor/version.rb +1 -1
- data/spec/default_spec.rb +9 -0
- metadata +3 -3
@@ -11,7 +11,7 @@ module DslAccessor
|
|
11
11
|
if !dsl_accessor_key?(key)
|
12
12
|
# load default value
|
13
13
|
default = dsl_accessor_get("#{key}_default")
|
14
|
-
value = default ? default
|
14
|
+
value = default ? instance_eval(&default) : nil
|
15
15
|
dsl_accessor_writer(key, value)
|
16
16
|
end
|
17
17
|
dsl_accessor_get(key)
|
data/lib/dsl_accessor/version.rb
CHANGED
data/spec/default_spec.rb
CHANGED
@@ -36,4 +36,13 @@ describe DslAccessor do
|
|
36
36
|
k1.dsl_accessor :foo, :default=>proc{1}
|
37
37
|
k1.foo.should == 1
|
38
38
|
end
|
39
|
+
|
40
|
+
it "should call it in his own context when proc given" do
|
41
|
+
# ensure that no 'name' in this context
|
42
|
+
lambda { name }.should raise_error(NameError)
|
43
|
+
|
44
|
+
k1 = Class.new
|
45
|
+
k1.dsl_accessor :my_name, :default=>proc{self.name}
|
46
|
+
lambda { k1.my_name }.should_not raise_error
|
47
|
+
end
|
39
48
|
end
|
metadata
CHANGED