Sha256: 4d027c919e15ec74766355ba7005ae0a159caa9697d547a0df9c0e7b0e46ec0c

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require 'bait/objective_c/project'

module Bait
  module ObjectiveC
    class DependencyOrderer
      attr_accessor :errors, :order, :queue, :project
      def initialize path_array, project
        @project = project
        @queue = path_array
        @order = []
        @errors = []
      end

      def examine_file path
        return unless path && File.exists?(path)
        if @order.include? path
          return
        end
        imports_within(path).each do |name|
          examine_file @project.glob(name).first
        end
        @order << path
      end

      def imports_within path
        imports = []
        File.open(path, 'r') do |f|
          f.each_line do |line|
            if matches = line.match(/^#import "(.*)"/)
              imports << matches[1]
            end
          end
        end
      rescue => ex
        @errors << ex
      ensure
        return imports
      end

      def start
        @queue.each do |path|
          examine_file path
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bait-0.3.2 lib/bait/objective_c/dependency_orderer.rb
bait-0.3.1 lib/bait/objective_c/dependency_orderer.rb
bait-0.3.0 lib/bait/objective_c/dependency_orderer.rb