Sha256: 14a8c7438a205476ac03c0bf81d5c4b002924884e9e787964a1257847a24ef18
Contents?: true
Size: 1.08 KB
Versions: 22
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module GrapeSwagger class ModelParsers include Enumerable def initialize @parsers = {} end def register(klass, ancestor) @parsers[klass] = ancestor.to_s end def insert_before(before_klass, klass, ancestor) subhash = @parsers.except(klass).to_a insert_at = subhash.index(subhash.assoc(before_klass)) insert_at = subhash.length - 1 if insert_at.nil? @parsers = Hash[subhash.insert(insert_at, [klass, ancestor])] end def insert_after(after_klass, klass, ancestor) subhash = @parsers.except(klass).to_a insert_at = subhash.index(subhash.assoc(after_klass)) insert_at = subhash.length - 1 if insert_at.nil? @parsers = Hash[subhash.insert(insert_at + 1, [klass, ancestor])] end def each @parsers.each_pair do |klass, ancestor| yield klass, ancestor end end def find(model) GrapeSwagger.model_parsers.each do |klass, ancestor| return klass if model.ancestors.map(&:to_s).include?(ancestor) end nil end end end
Version data entries
22 entries across 22 versions & 1 rubygems