Class: Evil::Client::DSL::Operations

Inherits:
Object
  • Object
show all
Defined in:
lib/evil/client/dsl/operations.rb

Overview

Container for operations definitions Applies settings to definitions and returns a final schema

Instance Method Summary collapse

Instance Method Details

#finalize(settings) ⇒ Hash<Symbol, Object>

Applies settings to all definitions and returns a final schema

Parameters:

  • settings (Object)

Returns:

  • (Hash<Symbol, Object>)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/evil/client/dsl/operations.rb', line 21

def finalize(settings)
  default = @schema[nil].finalize(settings)
  custom  = @schema.select { |key| key }

  schema = custom.each_with_object({}) do |(key, operation), hash|
    custom = operation.finalize(settings)
    hash[key] = default.merge(custom)
    hash[key][:format] ||= "json"
    hash[key][:responses] = default[:responses].merge(custom[:responses])
  end

  Verifier.call(schema)
end

#register(key, &block) ⇒ self

Adds block definition as a named operation

Parameters:

  • key (#to_sym)
  • block (Proc)

Returns:

  • (self)


11
12
13
14
# File 'lib/evil/client/dsl/operations.rb', line 11

def register(key, &block)
  @schema[key] = Operation.new(key, block)
  self
end