Sha256: 4c846e5a7cdd9cee6bf3e62f01a6ee427b0ea155d604b1389d65887b7f728140

Contents?: true

Size: 1.99 KB

Versions: 5

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

module Vedeu

  module DSL

    # Provides DSL methods for Vedeu::Geometries::Geometry objects.
    #
    # @api public
    #
    module Geometry

      # @macro module_singleton_methods
      module SingletonMethods

        # {include:file:docs/dsl/by_method/geometry.md}
        # @macro param_name
        # @param block [Proc]
        # @macro raise_requires_block
        # @macro raise_missing_required
        # @return [Vedeu::Geometries::Geometry]
        # @see Vedeu::Geometries::DSL
        def geometry(name = nil, &block)
          # Alternative implementation which treats `Vedeu.geometry`
          # as `Vedeu.geometries` if no name or block is given.
          #
          # if name && block_given?
          #   Vedeu::Geometries::Geometry.build(name: name, &block).store
          #
          # else
          #   Vedeu.geometries
          #
          # end

          raise Vedeu::Error::MissingRequired unless name
          raise Vedeu::Error::RequiresBlock unless block_given?

          Vedeu::Geometries::Geometry.build(name: name, &block).store
        end

      end # SingletonMethods

      # Provide additional behaviour as instance methods.
      #
      module InstanceMethods

        # {include:file:docs/dsl/by_method/geometry.md}
        # @macro param_name
        # @param block [Proc]
        # @macro raise_requires_block
        # @macro raise_missing_required
        # @return [Vedeu::Geometries::Geometry]
        # @see Vedeu::Geometries::DSL
        def geometry(name = nil, &block)
          raise Vedeu::Error::RequiresBlock unless block_given?

          model_name = name ? name : model.name

          Vedeu::Geometries::Geometry.build(name: model_name, &block).store
        end

      end # InstanceMethods

      # @macro module_included
      def self.included(klass)
        klass.extend(Vedeu::DSL::Geometry::SingletonMethods)
        klass.include(Vedeu::DSL::Geometry::InstanceMethods)
      end

    end # Geometry

  end # DSL

end # Vedeu

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vedeu-0.8.20 lib/vedeu/dsl/geometry.rb
vedeu-0.8.19 lib/vedeu/dsl/geometry.rb
vedeu-0.8.18 lib/vedeu/dsl/geometry.rb
vedeu-0.8.17 lib/vedeu/dsl/geometry.rb
vedeu-0.8.16 lib/vedeu/dsl/geometry.rb