13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/simplify_api/simplify_api.rb', line 13
def attribute(attr, type = Object, **args)
raise ArgumentError, "Duplicate attribute #{attr}." if self.attributes[attr]
if type.class == Array then
args[:default] = [] unless args[:default]
args[:array_type] = type[0]
end
self.attributes[attr] = {
name: attr.to_s,
type: type.class == Class ? type : type.class == Array ? Array : Object,
params: args
}
self.mandatory << attr if args[:mandatory]
self.default["#{attr}".to_sym] = args[:default] if args[:default]
self.attributes[attr]
end
|