Sha256: 5bde136ab435fd4a79b42e402c06b925319ad3abd7c649ae2be1ace1a42ab23a

Contents?: true

Size: 1.85 KB

Versions: 38

Compression:

Stored size: 1.85 KB

Contents

module Librarian
  class Lockfile
    class Compiler

      attr_accessor :environment
      private :environment=

      def initialize(environment)
        self.environment = environment
      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
        environment.dsl_class
      end

    end
  end
end

Version data entries

38 entries across 38 versions & 5 rubygems

Version Path
librarianp-1.1.2 lib/librarian/lockfile/compiler.rb
librarianp-1.1.1 lib/librarian/lockfile/compiler.rb
librarianp-1.1.0 lib/librarian/lockfile/compiler.rb
librarianp-1.0.0 lib/librarian/lockfile/compiler.rb
librarianp-0.6.4 lib/librarian/lockfile/compiler.rb
librarianp-0.6.3 lib/librarian/lockfile/compiler.rb
librarianp-0.6.2 lib/librarian/lockfile/compiler.rb
librarianp-0.6.1 lib/librarian/lockfile/compiler.rb
librarianp-0.6.0 lib/librarian/lockfile/compiler.rb
librarianp-0.5.1 lib/librarian/lockfile/compiler.rb
librarianp-0.5.0 lib/librarian/lockfile/compiler.rb
librarianp-0.4.0 lib/librarian/lockfile/compiler.rb
librarianp-0.3.0 lib/librarian/lockfile/compiler.rb
librarianp-0.2.0 lib/librarian/lockfile/compiler.rb
librarianp-0.1.2 lib/librarian/lockfile/compiler.rb
librarian-0.1.2 lib/librarian/lockfile/compiler.rb
librarian-puppet-0.9.10 vendor/librarian/lib/librarian/lockfile/compiler.rb
librarian-0.1.1 lib/librarian/lockfile/compiler.rb
librarian-puppet-0.9.9 vendor/librarian/lib/librarian/lockfile/compiler.rb
librarian-0.1.0 lib/librarian/lockfile/compiler.rb