Sha256: afd7340df47edcf3a30f679246116b384ecfe84aa505ff13d91bbaeb02c3e4cd

Contents?: true

Size: 916 Bytes

Versions: 4

Compression:

Stored size: 916 Bytes

Contents

# frozen_string_literal: true

module CobraCommander
  module Dependencies
    # Calculates ruby bundler dependencies
    class Bundler
      def initialize(root)
        @definition = ::Bundler::Definition.build(
          Pathname.new(File.join(root, "Gemfile")).realpath,
          Pathname.new(File.join(root, "Gemfile.lock")).realpath,
          false
        )
      end

      def path
        @definition.lockfile
      end

      def dependencies
        @definition.dependencies.map(&:name)
      end

      def components
        components_source.specs.map do |spec|
          { path: spec.loaded_from, name: spec.name, dependencies: spec.dependencies.map(&:name) }
        end
      end

    private

      def components_source
        @components_source ||= @definition.send(:sources).path_sources.find do |source|
          source.path.to_s.eql?("components")
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cobra_commander-0.9.0 lib/cobra_commander/dependencies/bundler.rb
cobra_commander-0.8.1 lib/cobra_commander/dependencies/bundler.rb
cobra_commander-0.8.0 lib/cobra_commander/dependencies/bundler.rb
cobra_commander-0.7.0 lib/cobra_commander/dependencies/bundler.rb