Sha256: b2d3525009988e59bc14e3c02faf5b303afcabed7c33f0466692257f04b7d45e
Contents?: true
Size: 1.05 KB
Versions: 6
Compression:
Stored size: 1.05 KB
Contents
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
6 entries across 6 versions & 1 rubygems