21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/crazy_doll/config.rb', line 21
def self.setup_class(klass)
klass.class_eval do
def crazy_doll_setuped?
@owner and @key and @description ? true : false
end
alias :crazy_doll_setuped :crazy_doll_setuped?
[['owner', 'to_s'], ['key', 'to_sym'], ['description', 'to_s']].each do |name,m|
class_eval <<-EVAL
def #{name}
@#{name} || nil
end
def #{name}=(value)
raise ArgumentError, "can't redefine #{name}" if defined?(@#{name})
@#{name} = value.#{m}
end
EVAL
end
alias :__to_yaml :to_yaml
def _to_yaml(opts = {})
return __to_yaml(opts) unless crazy_doll_setuped?
a, b, c = @owner, @key, @description
['@owner', '@key', '@description'].each { |x| remove_instance_variable(x) }
begin
return __to_yaml(opts)
ensure
@owner, @key, @description = a, b, c
end
end
def to_yaml( opts = {} )
return 'YES SIR !' if opts == 'class_setuped?'
return _to_yaml(opts) unless crazy_doll_setuped?
YAML.quick_emit( self.object_id, opts ) do |out|
out.map( "tag:crazydoll.org,2010:ConfigVar", "crazydoll.org,2010/ConfigVar" ) do |map|
map.add('owner', self.owner )
map.add('key', self.key )
map.add('description', self.description)
map.add('value', self._to_yaml )
end
end
end
end
end
|