Sha256: 1144a77a1529220fe0edaf081845c204ce9e8883621f4654d0cb9a847765da89

Contents?: true

Size: 1.76 KB

Versions: 12

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

module Vedeu

  # Provides a mechanism to help configure and use Vedeu.
  #
  module DSL

    # Returns a new instance of the DSL class including {Vedeu::DSL}.
    #
    # @param model [void] The model class which the DSL class is
    #   wrapping.
    # @param client [void] The class where the DSL methods are being
    #   used.
    # @return [void] An instance of the DSL class.
    def initialize(model, client = nil)
      @model  = model
      @client = client
    end

    # Returns the model name if available.
    #
    # @return [NilClass|String|Symbol]
    def name
      return nil unless model

      model.name
    end

    protected

    # @!attribute [r] client
    # @return [Object] The object instance where the DSL is being
    #   used.
    attr_reader :client

    # @!attribute [r] model
    # @return [void] The new model object which the DSL is
    #   constructing.
    attr_reader :model

    private

    # Returns the default attributes for the new model.
    #
    # @note
    #   Specific DSL classes may be overriding this method.
    #
    # @return [Hash<Symbol => void>]
    def attributes
      {
        client: client,
        parent: model,
      }
    end

    # :nocov:

    # Attempts to find the missing method on the client object.
    #
    # @param method [Symbol] The name of the method sought.
    # @param args [Array] The arguments which the method was to be
    #   invoked with.
    # @macro param_block
    # @return [void]
    def method_missing(method, *args, &block)
      Vedeu.log(type:    :debug,
                message: "!!!method_missing '#{method}' sending to " \
                         "#{client.inspect}")

      client.send(method, *args, &block) if client
    end

    # :nocov:

  end # DSL

end # Vedeu

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vedeu-0.8.32 lib/vedeu/dsl/dsl.rb
vedeu-0.8.31 lib/vedeu/dsl/dsl.rb
vedeu-0.8.30 lib/vedeu/dsl/dsl.rb
vedeu-0.8.29 lib/vedeu/dsl/dsl.rb
vedeu-0.8.28 lib/vedeu/dsl/dsl.rb
vedeu-0.8.27 lib/vedeu/dsl/dsl.rb
vedeu-0.8.26 lib/vedeu/dsl/dsl.rb
vedeu-0.8.25 lib/vedeu/dsl/dsl.rb
vedeu-0.8.24 lib/vedeu/dsl/dsl.rb
vedeu-0.8.23 lib/vedeu/dsl/dsl.rb
vedeu-0.8.22 lib/vedeu/dsl/dsl.rb
vedeu-0.8.21 lib/vedeu/dsl/dsl.rb