Sha256: 8431e726bd90076c2128b719962e77b459fd4de370f49dea6b541e883cafd752
Contents?: true
Size: 1.18 KB
Versions: 13
Compression:
Stored size: 1.18 KB
Contents
module ApiRegulator class SharedSchema attr_reader :name, :description, :params def initialize(name, description, &block) @name = name @description = description @params = [] instance_eval(&block) if block_given? end def param(name, type = nil, item_type: nil, desc: "", location: :body, **options, &block) param = Param.new(name, type, item_type: item_type, desc: desc, location: location, **options, &block) @params << param end end @shared_schemas = {} @shared_schema_registry = {} class << self attr_accessor :shared_schema_registry def shared_schemas shared_schema_registry.each do |name, (description, block)| @shared_schemas[name] = SharedSchema.new(name, description, &block) end @shared_schemas end def shared_schema(name) if shared_schema_registry[name] description, block = shared_schema_registry.delete(name) @shared_schemas[name] = SharedSchema.new(name, description, &block) end @shared_schemas[name] end def register_shared_schema(name, description, &block) shared_schema_registry[name] = [description, block] end end end
Version data entries
13 entries across 13 versions & 1 rubygems