open_dsl 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -8,7 +8,7 @@ require 'open_dsl/context'
8
8
  require 'open_dsl/eval_stack'
9
9
 
10
10
  module OpenDsl
11
- VERSION = '0.2'
11
+ VERSION = '0.3'
12
12
  end
13
13
 
14
14
  def open_dsl(&blk)
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: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- version: "0.2"
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-11 00:00:00 +11:00
17
+ date: 2010-11-12 00:00:00 +11:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency