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
|
# File 'lib/attrio.rb', line 28
def define_attributes(options = {}, &block)
as = options.delete(:as) || :attributes
self.attrio[as] = options
class_eval(" @\#{as} ||= {}\n\n class << self\n def \#{as}(attributes = [])\n attributes = Helpers.to_a(attributes).flatten\n return @\#{as} if attributes.empty?\n\n attributes = @\#{as}.keys & attributes\n @\#{as}.select{ |k,v| attributes.include?(k) }\n end\n\n def inherited(subclass)\n subclass.instance_variable_set(\"@\#{as}\", instance_variable_get(\"@\#{as}\").dup)\n end\n end\n\n def \#{as}(attributes = [])\n # self.class.\#{as}(attributes)\n\n attributes = Helpers.to_a(attributes).flatten\n return @\#{as} if attributes.empty?\n\n attributes = @\#{as}.keys & attributes\n @\#{as}.select{ |k,v| attributes.include?(k) }\n end\n EOS\n\n self.define_attrio_reset(as)\n\n Attrio::AttributesParser.new(self, as, &block)\nend\n", __FILE__, __LINE__ + 1)
|