lib/render/attributes/attribute.rb in render-0.0.8 vs lib/render/attributes/attribute.rb in render-0.0.9
- old
+ new
@@ -3,42 +3,58 @@
module Render
class Attribute
SCHEMA_IDENTIFIERS = [:properties, :items].freeze
attr_accessor :name,
- :type,
+ :types,
:schema,
:enums,
:format,
- :required
+ :min_length,
+ :max_length,
+ :multiple_of,
+ :minimum,
+ :maximum,
+ :exclusive_minimum,
+ :exclusive_maximum
+ attr_writer :default
+
def initialize(options = {})
Render.logger.debug("Initializing attribute #{options}")
- self.required = false
end
def bias_type
- format || type
+ format || types.first
end
def default_value
- Render.live ? nil : faux_value
+ @default || (Render.live ? nil : faux_value)
end
def nested_schema?(options = {})
options.any? { |name, value| SCHEMA_IDENTIFIERS.include?(name) }
end
private
- def process_type!(options)
- self.type = Type.parse!(options[:type])
+ def process_options!(options)
+ self.types = [Type.parse!(options[:type])].flatten
self.format = Type.parse(options[:format])
if (options[:enum])
self.enums = options[:enum]
self.format = Type::Enum
end
+
+ @default = options[:default]
+ self.min_length = options[:minLength]
+ self.max_length = options[:maxLength]
+ self.multiple_of = options[:multipleOf]
+ self.minimum = options[:minimum]
+ self.maximum = options[:maximum]
+ self.exclusive_minimum = !!options[:exclusiveMinimum]
+ self.exclusive_maximum = !!options[:exclusiveMaximum]
end
def faux_value
Generator.trigger(bias_type, name, self)
end