Sha256: 331c1e494dec5fc0c5c5ff402d8855d03cb26a2b63e7c7b86a8169ca8f7f3a8c

Contents?: true

Size: 839 Bytes

Versions: 1

Compression:

Stored size: 839 Bytes

Contents

module Sunzi
  class Dependency < Struct.new(:name, :version)

    @list = {}

    def initialize(*args)
      super
      self.class.list[name] = self
    end

    class << self
      attr_accessor :list

      def load(key)
        unless dependency = @list[key]
          fail "#{key} is not initialized. Run Sunzi::Dependency.new('#{key}', '~> ...')"
        end

        name, version = dependency.name, dependency.version

        begin
          gem(name, version)
          require(name)
        rescue LoadError
          base = GemRoot.join('templates/dependency')
          which = if $!.to_s =~ /Gemfile/
            'gemfile'
          else
            'install'
          end
          text = ERB.new(base.join("#{which}.erb").read, nil, '-').result(binding)
          abort_with text
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sunzi-2.0.0 lib/sunzi/dependency.rb