Module: ElasticGraph::Support::Config

Defined in:
elasticgraph-support/lib/elastic_graph/support/config.rb

Overview

Provides a standard way to define an ElasticGraph configuration class.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.define(*attrs) {|::Data| ... } ⇒ ::Class

Defines a configuration class with the given attributes.

Examples:

Define a configuration class

require "elastic_graph/support/config"

ExampleConfigClass = ElasticGraph::Support::Config.define(:size, :name) do
  json_schema at: "example", optional: false,
    properties: {
      size: {
        description: "Determines the size.",
        examples: [10, 100],
        type: "integer",
        minimum: 1,
      },
      name: {
        description: "Determines the name.",
        examples: ["widget"],
        type: "string",
        minLength: 1
      }
    },
    required: ["size", "name"]
end

Parameters:

  • attrs (::Symbol)

    attribute names

Yields:

  • (::Data)

    the body of the class (similar to ::Data.define)

Returns:

  • (::Class)

    the defined configuration class



46
47
48
49
50
51
52
53
54
# File 'elasticgraph-support/lib/elastic_graph/support/config.rb', line 46

def self.define(*attrs, &block)
  ::Data.define(*attrs) do
    # @implements ::Data
    alias_method :__data_initialize, :initialize
    extend ClassMethods
    include InstanceMethods
    class_exec(&(_ = block)) if block
  end
end