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
|
# File 'lib/aliyun/log/record/field.rb', line 28
def field(name, options = {})
type = options[:type] || :text
unless PERMITTED_KEY_TYPES.include?(type)
raise ArgumentError, "Field #{name} type(#{type}) error, key type only support text/long/double/json"
end
named = name.to_s
if options[:log_tag]
self.tag_attributes = tag_attributes.merge(name => { type: type }.merge(options))
else
self.attributes = attributes.merge(name => { type: type }.merge(options))
end
warn_about_method_overriding(name, name)
warn_about_method_overriding("#{named}=", name)
warn_about_method_overriding("#{named}?", name)
define_attribute_method(name)
generated_methods.module_eval do
define_method(named) { read_attribute(named) }
define_method("#{named}?") do
value = read_attribute(named)
case value
when true then true
when false, nil then false
else
!value.nil?
end
end
define_method("#{named}=") { |value| write_attribute(named, value) }
end
end
|