GEM has_metadata 中有如下代码,虽然明白这个属性是获得方法定义,却找不到在哪定义?
fields.each do |name, options|
# delegate all attribute methods to the metadata
attribute_method_matchers.each { |matcher| delegate matcher.method_name(name), to: :metadata! }
if options.kind_of?(Hash) then
type = options.delete(:type)
type_validate = !options.delete(:skip_type_validation)
options.delete :default
validate do |obj|
value = obj.send(name)
errors.add(name, :incorrect_type) unless HasMetadata.metadata_typecast(value, type).kind_of?(type) or
((options[:allow_nil] and value.nil?) or (options[:allow_blank] and value.blank?))
end if type && type_validate
validates(name, options) unless options.empty? or (options.keys - [:allow_nil, :allow_blank]).empty?
end
end