Sha256: 08b0bb9ae7fc702b26f13ba2409e554502ec5686f95394d60acdf5a7fc60a0ad

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# encoding: utf-8

class AbstractMapper

  # Collection of DSL commands used by the builder
  #
  # @api private
  #
  class Commands

    # @!scope class
    # @!method new(registry = {})
    # Creates an immutable collection of commands
    #
    # @param [Hash] registry
    #
    # @return [Faceter::Commands]

    # @private
    def initialize(registry = {})
      @registry = registry.dup
      IceNine.deep_freeze(self)
    end

    # Returns a new immutable registry with added command name and type
    #
    # @param [[Symbol, Class, Proc]] other
    #
    # @return [undefined]
    #
    def <<(other)
      command = Command.new(*other)
      self.class.new @registry.merge(command.name => command)
    end

    # Returns the registered command by name
    #
    # @param [#to_sym] name The name of the command
    #
    # @return [AbstractMapper::Command]
    #
    # @raise [AbstractMapper::Errors::UnknownCommand]
    #   When unknown command is called
    #
    def [](name)
      @registry.fetch(name.to_sym) { fail(Errors::UnknownCommand.new name) }
    end

  end # class Commands

end # class AbstractMapper

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
abstract_mapper-0.0.2 lib/abstract_mapper/commands.rb