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 " def \#{name}\n @\#{name} || nil\n end\n\n def \#{name}=(value)\n raise ArgumentError, \"can't redefine \#{name}\" if defined?(@\#{name})\n @\#{name} = value.\#{m}\n end\n EVAL\n end\n\n alias :__to_yaml :to_yaml\n\n def _to_yaml(opts = {})\n return __to_yaml(opts) unless crazy_doll_setuped?\n a, b, c = @owner, @key, @description\n ['@owner', '@key', '@description'].each { |x| remove_instance_variable(x) }\n begin\n return __to_yaml(opts)\n ensure\n @owner, @key, @description = a, b, c\n end\n end\n\n def to_yaml( opts = {} )\n return 'YES SIR !' if opts == 'class_setuped?'\n return _to_yaml(opts) unless crazy_doll_setuped?\n YAML.quick_emit( self.object_id, opts ) do |out|\n out.map( \"tag:crazydoll.org,2010:ConfigVar\", \"crazydoll.org,2010/ConfigVar\" ) do |map|\n map.add('owner', self.owner )\n map.add('key', self.key )\n map.add('description', self.description)\n map.add('value', self._to_yaml )\n end\n end\n end\n end\nend\n"
|