Sha256: 3974776c967978dc703632313be68ac068387372a222b128520aa30b7a45a128

Contents?: true

Size: 1.88 KB

Versions: 9

Compression:

Stored size: 1.88 KB

Contents

require 'librarian/helpers/debug'

module Librarian
  class Lockfile
    class Compiler

      include Helpers::Debug

      attr_reader :root_module

      def initialize(root_module)
        @root_module = root_module
      end

      def compile(resolution)
        out = StringIO.new
        save_sources(out, resolution.manifests)
        save_dependencies(out, resolution.dependencies)
        out.string
      end

    private

      def save_sources(out, manifests)
        dsl_class.source_types.map{|t| t[1]}.each do |type|
          type_manifests = manifests.select{|m| type === m.source}
          sources = type_manifests.map{|m| m.source}.uniq.sort_by{|s| s.to_s}
          sources.each do |source|
            source_manifests = type_manifests.select{|m| source == m.source}
            save_source(out, source, source_manifests)
          end
        end
      end

      def save_source(out, source, manifests)
        out.puts "#{source.class.lock_name}"
        options = source.to_lock_options
        remote = options.delete(:remote)
        out.puts "  remote: #{remote}"
        options.to_a.sort_by{|a| a[0].to_s}.each do |o|
          out.puts "  #{o[0]}: #{o[1]}"
        end
        out.puts "  specs:"
        manifests.sort_by{|a| a.name}.each do |manifest|
          out.puts "    #{manifest.name} (#{manifest.version})"
          manifest.dependencies.sort_by{|a| a.name}.each do |dependency|
            out.puts "      #{dependency.name} (#{dependency.requirement})"
          end
        end
        out.puts ""
      end

      def save_dependencies(out, dependencies)
        out.puts "DEPENDENCIES"
        dependencies.sort_by{|a| a.name}.each do |d|
          res = "#{d.name}"
          res << " (#{d.requirement})" if d.requirement
          out.puts "  #{res}"
        end
        out.puts ""
      end

      def dsl_class
        root_module.dsl_class
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
librarian-0.0.9 lib/librarian/lockfile/compiler.rb
librarian-0.0.8 lib/librarian/lockfile/compiler.rb
librarian-0.0.7 lib/librarian/lockfile/compiler.rb
librarian-0.0.6 lib/librarian/lockfile/compiler.rb
librarian-0.0.5 lib/librarian/lockfile/compiler.rb
librarian-0.0.4 lib/librarian/lockfile/compiler.rb
librarian-0.0.3 lib/librarian/lockfile/compiler.rb
librarian-0.0.2 lib/librarian/lockfile/compiler.rb
librarian-0.0.1 lib/librarian/lockfile/compiler.rb