Module: OAPI::Properties::ClassMethods
- Defined in:
- lib/oapi/properties.rb
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
-
#property(name, object = nil) ⇒ Object
rubocop:disable Metrics/MethodLength.
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
5 6 7 |
# File 'lib/oapi/properties.rb', line 5 def properties @properties end |
Instance Method Details
#property(name, object = nil) ⇒ Object
rubocop:disable Metrics/MethodLength
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/oapi/properties.rb', line 7 def property(name, object = nil) # rubocop:disable Metrics/MethodLength @properties ||= {} @properties[name] = object define_method(name) do |value = nil, ref: nil, &block| if object.nil? raise ArgumentError, "value must be passed" if value.nil? return instance_variable_set(:"@#{name}", value) end if [NilClass, object, OAPI::Ref].none? { value.is_a?(_1) } raise ArgumentError, "given value must be of type #{object} or #{OAPI::Ref} given: #{value}" end raise ArgumentError, "ref and block are mutual exclusive" if ref && block instance_variable_set(:"@#{name}", parse_property_value(value, object, ref, block)) end end |