Module: Apicraft::Mocker

Defined in:
lib/apicraft/mocker.rb,
lib/apicraft/mocker/base.rb,
lib/apicraft/mocker/array.rb,
lib/apicraft/mocker/all_of.rb,
lib/apicraft/mocker/any_of.rb,
lib/apicraft/mocker/number.rb,
lib/apicraft/mocker/object.rb,
lib/apicraft/mocker/one_of.rb,
lib/apicraft/mocker/string.rb,
lib/apicraft/mocker/boolean.rb,
lib/apicraft/mocker/integer.rb

Overview

Namespace module for Mocker types

Defined Under Namespace

Classes: AllOf, AnyOf, Array, Base, Boolean, Integer, Number, Object, OneOf, String

Class Method Summary collapse

Class Method Details

.extract_type(schema) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/apicraft/mocker.rb', line 31

def self.extract_type(schema)
  return schema.type if schema.type.present?

  return "one_of" if schema.one_of.present?

  return "any_of" if schema.any_of.present?

  "all_of" if schema.all_of.present?
end

.handler_for(schema) ⇒ Object



17
18
19
20
21
# File 'lib/apicraft/mocker.rb', line 17

def self.handler_for(schema)
  "Apicraft::Mocker::#{
    extract_type(schema).camelize
  }".constantize
end

.mock(schema) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/apicraft/mocker.rb', line 23

def self.mock(schema)
  return if schema.blank?

  handler_for(schema).new(
    schema
  ).mock
end