Class: Evil::Client::Schema::Scope

Inherits:
Operation show all
Defined in:
lib/evil/client/schema/scope.rb

Overview

Mutable container of definitions for sub-scopes and operations with DSL to configure those definitions.

Instance Attribute Summary

Attributes inherited from Evil::Client::Schema

#client, #name, #parent

Instance Method Summary collapse

Methods inherited from Operation

#body, #definitions, #format, #headers, #http_method, #middleware, #path, #query, #response, #security

Methods inherited from Evil::Client::Schema

#let, #option, #settings, #to_s, #validate

Instance Method Details

#leaf?false

Tells that this is a schema for a scope (not the final operation)

Returns:

  • (false)


13
14
15
# File 'lib/evil/client/schema/scope.rb', line 13

def leaf?
  false
end

#operation(name, &block) ⇒ self

Creates or updates operation definition

Parameters:

  • name (#to_sym)

    The unique name of operation inside the scope

  • block (Proc)

    The block containing definition for the operation

Returns:

  • (self)


55
56
57
58
59
60
61
# File 'lib/evil/client/schema/scope.rb', line 55

def operation(name, &block)
  key = NameError.check!(name)
  TypeError.check! self, key, :operation
  @__children__[key] ||= self.class.superclass.new(self, key)
  @__children__[key].instance_exec(&block)
  self
end

#operationsHash<[Symbol, nil], Class>

The collection of named operation schemas

Returns:

  • (Hash<[Symbol, nil], Class>)


31
32
33
# File 'lib/evil/client/schema/scope.rb', line 31

def operations
  @__children__.select { |_, child| child.leaf? }
end

#scope(name, &block) ⇒ self

Creates or updates sub-scope definition

Parameters:

  • name (#to_sym)

    The unique name of subscope inside current scope

  • block (Proc)

    The block containing definition for the subscope

Returns:

  • (self)


41
42
43
44
45
46
47
# File 'lib/evil/client/schema/scope.rb', line 41

def scope(name, &block)
  key = NameError.check!(name)
  TypeError.check! self, key, :scope
  @__children__[key] ||= self.class.new(self, key)
  @__children__[key].instance_exec(&block)
  self
end

#scopesHash<Symbol, Class>

The collection of named sub-scope schemas

Every sub-scope schema refers to the current one as a [#parent]

Returns:

  • (Hash<Symbol, Class>)


23
24
25
# File 'lib/evil/client/schema/scope.rb', line 23

def scopes
  @__children__.reject { |_, child| child.leaf? }
end