open_dsl 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/open_dsl/context.rb +7 -0
- data/lib/open_dsl.rb +1 -1
- metadata +4 -4
data/lib/open_dsl/context.rb
CHANGED
@@ -6,6 +6,7 @@ module OpenDsl
|
|
6
6
|
def initialize(const_name, &blk)
|
7
7
|
@stack = EvalStack.new(self)
|
8
8
|
if constant_or_constant_name?(const_name)
|
9
|
+
@toplevel_object_already_exists = existing_class?(const_name)
|
9
10
|
@toplevel_object = new_instance(const_name)
|
10
11
|
else
|
11
12
|
@toplevel_object = Array.new
|
@@ -71,6 +72,7 @@ module OpenDsl
|
|
71
72
|
|
72
73
|
def define_getter_and_setter_if_needed(name)
|
73
74
|
return if name.respond_to?("#{name}=")
|
75
|
+
raise "Expected #{@toplevel_object.class.name} to have defined a setter method for '#{name}'" if @toplevel_object_already_exists
|
74
76
|
|
75
77
|
@stack.bottom.class.instance_eval do
|
76
78
|
define_method("#{name}=") do |value|
|
@@ -87,6 +89,11 @@ module OpenDsl
|
|
87
89
|
get_or_define_const(const_name).new
|
88
90
|
end
|
89
91
|
|
92
|
+
def existing_class?(name_or_const)
|
93
|
+
return true if name_or_const.is_a?(Class)
|
94
|
+
Object.const_defined?(name_or_const)
|
95
|
+
end
|
96
|
+
|
90
97
|
def get_or_define_const(name_or_const)
|
91
98
|
return name_or_const if name_or_const.is_a?(Class)
|
92
99
|
Object.const_defined?(name_or_const) ? Object.const_get(name_or_const) : Object.const_set(name_or_const, Class.new)
|
data/lib/open_dsl.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ian Leitch
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-12 00:00:00 +11:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|