Sha256: 94ccb6262aa01c44cf23a15d99f063a79233f58beaa197f1e58de54b887ec7db

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 KB

Contents

module Inch
  module CLI
    module Command
      # Base class for Command objects concerned with clearly specified
      # objects.
      #
      # Commands subclassing from this class are called with a list of object
      # names (most commonly only one) in the form:
      #
      #   $ inch COMMAND [paths] OBJECT_NAME [, OBJECT_NAME2, ...] [options]
      #
      # @abstract
      class BaseObject < Base
        attr_accessor :object, :objects

        def initialize
          super
          @ranges = Evaluation.new_score_ranges
        end

        # Prepares the given objects, parsing arguments and
        # running the source parser.
        #
        # @param *args [Array<String>] the list of arguments
        # @return [void]
        def prepare_objects(*args)
          @options.parse(args)
          @options.verify
          run_source_parser(@options.paths, @options.excluded)

          self.objects = find_objects_with_names(@options.object_names)
          self.object = @objects.first
        end

        private

        # Returns all objects matching the given +object_names+
        #
        # @param object_names [Array<String>]
        # @return [Array<CodeObject::Proxy::Base>]
        def find_objects_with_names(object_names)
          object_names.map do |object_name|
            if object = source_parser.find_object(object_name)
              object
            else
              source_parser.find_objects(object_name)
            end
          end.flatten
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
inch-0.2.2 lib/inch/cli/command/base_object.rb
inch-0.2.1 lib/inch/cli/command/base_object.rb
inch-0.2.0 lib/inch/cli/command/base_object.rb
inch-0.1.4 lib/inch/cli/command/base_object.rb