Sha256: b9e36a9ca64f4b2a54489249b3f032962b934700cc4dadf55d9bb5948befbd0a
Contents?: true
Size: 1.56 KB
Versions: 13
Compression:
Stored size: 1.56 KB
Contents
module OasRails module Spec module Specable def oas_fields [] end def to_spec hash = {} oas_fields.each do |var| key = var.to_s camel_case_key = key.camelize(:lower).to_sym value = send(var) processed_value = if value.respond_to?(:to_spec) value.to_spec elsif value.is_a?(Array) && value.all? { |elem| elem.respond_to?(:to_spec) } value.map(&:to_spec) # elsif value.is_a?(Hash) # hash = {} # value.each do |key, object| # hash[key] = object.to_spec # end # hash else value end hash[camel_case_key] = processed_value unless valid_processed_value?(processed_value) end hash end # rubocop:disable Lint/UnusedMethodArgument def as_json(options = nil) to_spec end # rubocop:enable Lint/UnusedMethodArgument private def valid_processed_value?(processed_value) ((processed_value.is_a?(Hash) || processed_value.is_a?(Array)) && processed_value.empty?) || processed_value.nil? end def snake_to_camel(snake_str) words = snake_str.to_s.split('_') words[1..].map!(&:capitalize) (words[0] + words[1..].join).to_sym end end end end
Version data entries
13 entries across 13 versions & 1 rubygems