class GrapeSwagger::ModelParsers

Public Class Methods

new() click to toggle source
# File lib/grape-swagger/model_parsers.rb, line 7
def initialize
  @parsers = {}
end

Public Instance Methods

each() { |klass, ancestor| ... } click to toggle source
# File lib/grape-swagger/model_parsers.rb, line 29
def each
  @parsers.each_pair do |klass, ancestor|
    yield klass, ancestor
  end
end
find(model) click to toggle source
# File lib/grape-swagger/model_parsers.rb, line 35
def find(model)
  GrapeSwagger.model_parsers.each do |klass, ancestor|
    return klass if model.ancestors.map(&:to_s).include?(ancestor)
  end
  nil
end
insert_after(after_klass, klass, ancestor) click to toggle source
# File lib/grape-swagger/model_parsers.rb, line 22
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 = subhash.insert(insert_at + 1, [klass, ancestor]).to_h
end
insert_before(before_klass, klass, ancestor) click to toggle source
# File lib/grape-swagger/model_parsers.rb, line 15
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 = subhash.insert(insert_at, [klass, ancestor]).to_h
end
register(klass, ancestor) click to toggle source
# File lib/grape-swagger/model_parsers.rb, line 11
def register(klass, ancestor)
  @parsers[klass] = ancestor.to_s
end