Sha256: 56ca077fafc5ad332c00cd1dd0e068b5b740509c6e9b78fe00c6ae23b5206fcf

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require "uri"

module Resona
  module Formula
    class << self
      def print(gems)
        puts generate_resource_stanzas(gems)
        puts
        puts install_method
      end

      def generate_resource_stanzas(gems)
        stanzas = gems.sort.map do |name, info|
          resource_stanza(name, info[:version], info[:platform],
                          info[:checksum], info[:remote_uri])
        end

        stanzas.join("\n\n")
      end


      private

      def resource_stanza(name, version, platform, checksum, remote_uri)
        uri = if platform.nil? || platform.empty?
                URI.join(remote_uri, "/gems/#{name}-#{version}.gem")
              else
                URI.join(remote_uri, "/gems/#{name}-#{version}-#{platform}.gem")
              end

        <<-EOL
resource "#{name}" do
  url "#{uri}"
  sha256 "#{checksum}"
end
        EOL
      end

      def install_method
        <<-EOL
def install
  resources.each do |r|
    r.verify_download_integrity(r.fetch)
    system("gem", "install", r.cached_download, "--no-document",
      "--install-dir", "\#{libexec}/vendor")
  end

  mkpath bin
  (bin/"__YOUR_FORMULA_SCRIPT__").write <<-EOS.undent
  #!/bin/bash
  export GEM_HOME="\#{libexec}/vendor"
  exec ruby __TARGET__ "$@"
  EOS

  # TODO: Continue installation
end
        EOL
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
resona-0.3.0 lib/resona/formula.rb