Sha256: e31ff7b1a4f371ed4d2114046afbd10410f627f9c805c6aac49d2013aa68f4b4

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

module Vedeu

  module DSL

    # DSL for adding interfaces to a group.
    #
    # @api public
    class Group

      include Vedeu::DSL

      # Specify a new group of interfaces with a simple DSL.
      #
      # The example below resembles 'vim' (the popular terminal-based text
      # editor):
      #
      # @example
      #   Vedeu.group 'title_screen' do
      #     add 'welcome_interface'
      #     # ...
      #   end
      #
      #   Vedeu.group 'main_screen' do
      #     add 'editor_interface'
      #     add 'status_interface'
      #     add 'command_interface'
      #     # ...
      #   end
      #
      # @note
      #   Creating a group with the same name as an existing group overwrites
      #   the existing group.
      #
      # @param name [String] The name of this group.
      # @param block [Proc]
      # @raise [Vedeu::InvalidSyntax] The required block was not given.
      # @return [Vedeu::Group]
      def self.group(name, &block)
        fail Vedeu::InvalidSyntax, 'block not given' unless block_given?

        Vedeu::Group.build({ name: name }, &block).store
      end

      # Returns an instance of DSL::Group.
      #
      # @param model [Vedeu::Group]
      # @param client [Object]
      # @return [Vedeu::DSL::Group]
      def initialize(model, client = nil)
        @model  = model
        @client = client
      end

      # Add the named interface to this group.
      #
      # @param interface_name [String]
      # @return [void]
      def add(interface_name)
        model.add(interface_name)
      end

      protected

      # @!attribute [r] client
      # @return [Object]
      attr_reader :client

      # @!attribute [r] model
      # @return [Vedeu::Group]
      attr_reader :model

    end # Group

  end # DSL

end # Vedeu

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.4.58 lib/vedeu/dsl/group.rb
vedeu-0.4.57 lib/vedeu/dsl/group.rb
vedeu-0.4.56 lib/vedeu/dsl/group.rb