Class: GrapeSwagger::ModelParsers
- Inherits:
-
Object
- Object
- GrapeSwagger::ModelParsers
- Includes:
- Enumerable
- Defined in:
- lib/grape-swagger/model_parsers.rb
Instance Method Summary collapse
- #each ⇒ Object
- #find(model) ⇒ Object
-
#initialize ⇒ ModelParsers
constructor
A new instance of ModelParsers.
- #insert_after(after_klass, klass, ancestor) ⇒ Object
- #insert_before(before_klass, klass, ancestor) ⇒ Object
- #register(klass, ancestor) ⇒ Object
Constructor Details
#initialize ⇒ ModelParsers
Returns a new instance of ModelParsers.
7 8 9 |
# File 'lib/grape-swagger/model_parsers.rb', line 7 def initialize @parsers = {} end |
Instance Method Details
#each ⇒ Object
29 30 31 32 33 |
# File 'lib/grape-swagger/model_parsers.rb', line 29 def each @parsers.each_pair do |klass, ancestor| yield klass, ancestor end end |
#find(model) ⇒ Object
35 36 37 38 39 40 |
# 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) ⇒ Object
22 23 24 25 26 27 |
# 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) ⇒ Object
15 16 17 18 19 20 |
# 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) ⇒ Object
11 12 13 |
# File 'lib/grape-swagger/model_parsers.rb', line 11 def register(klass, ancestor) @parsers[klass] = ancestor.to_s end |