Sha256: 396b61e5d3d8527df26ab09dce79874315335573fa2925392d8922bbbdb0a256

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

require 'hanami'
require 'hanami/environment'
require 'hanami/components'
require 'concurrent'

module Hanami
  module Commands
    # Abstract command
    #
    # @since 0.9.0
    class Command
      # @since 0.9.0
      # @api private
      def self.inherited(component)
        super

        component.class_eval do
          @_requirements = Concurrent::Array.new
          extend ClassMethods
        end
      end

      # Class level interface
      #
      # @since 0.9.0
      # @api private
      module ClassMethods
        # @since 0.9.0
        # @api private
        def register_as(name)
          Hanami::Components.register(name, self)
        end

        # @since 0.9.0
        # @api private
        def requires(*names)
          requirements.concat(names)
        end

        # @since 0.9.0
        # @api private
        def requirements
          @_requirements
        end
      end

      # @param options [Hash] Environment's options
      #
      # @since 0.9.0
      # @api private
      def initialize(options)
        @environment = Hanami::Environment.new(options)
        @environment.require_project_environment
        @configuration = Hanami.configuration

        requirements.resolved('environment', environment)
        requirements.resolve(self.class.requirements)
      end

      private

      # @since 0.9.0
      # @api private
      attr_reader :environment

      # @since 0.9.0
      # @api private
      attr_reader :configuration

      # @since 0.9.0
      # @api private
      def requirements
        Hanami::Components
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-1.0.0 lib/hanami/commands/command.rb
hanami-1.0.0.rc1 lib/hanami/commands/command.rb
hanami-1.0.0.beta3 lib/hanami/commands/command.rb