Module: SimplifyApi::ClassMethods
- Defined in:
- lib/simplify_api/simplify_api.rb
Overview
ClassMethods
Instance Method Summary collapse
Instance Method Details
#attribute(attr, type = Object, **args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/simplify_api/simplify_api.rb', line 13 def attribute(attr, type = Object, **args) raise ArgumentError, "Duplicate attribute #{attr}." if attributes[attr] if type.class == Array args[:default] = [] unless args[:default] args[:array_type] = type[0] end args[:mandatory] ||= false args[:default] ||= nil unless args[:default].class == FalseClass attributes[attr] = { name: attr.to_s, type: { Class => type, Array => Array }[type.class] || Object, params: args } attr end |