Sha256: 76c5189d8db59cda03c6caa07868f79f7fc765a781c0ae537f0e1cef6ba448f4

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

require 'bundler'

module IronWorkerNG
  module Feature
    module Ruby
      module MergeGemfile
        class Feature < IronWorkerNG::Feature::Base
          attr_reader :path
          attr_reader :groups

          def initialize(path, groups)
            @path = File.expand_path(path)
            @groups = groups
          end

          def hash_string
            Digest::MD5.hexdigest(@path + File.mtime(@path).to_i.to_s + (File.exists?(@path + '.lock') ? File.mtime(@path + '.lock').to_i.to_s : '') + @groups.join)
          end
        end

        module InstanceMethods
          def merge_gemfile(path, *groups)
            groups = groups.map { |g| g.to_sym }
            groups << :default if groups.length == 0

            IronCore::Logger.info 'IronWorkerNG', "Adding ruby gems dependencies from #{groups.join(', ')} group#{groups.length > 1 ? 's' : ''} of #{path}"

            specs = Bundler::Definition.build(path, path + '.lock', nil).specs_for(groups)

            specs.each do |spec|
              merge_gem(spec.name, spec.version.to_s)
            end

            @features << IronWorkerNG::Feature::Ruby::MergeGemfile::Feature.new(path, groups)
          end

          alias :gemfile :merge_gemfile

          def self.included(base)
            IronWorkerNG::Code::Base.register_feature(:name => 'merge_gemfile', :for_klass => base, :args => 'PATH[,GROUP...]')
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
iron_worker_ng-0.5.1 lib/iron_worker_ng/feature/ruby/merge_gemfile.rb
iron_worker_ng-0.5.0 lib/iron_worker_ng/feature/ruby/merge_gemfile.rb
iron_worker_ng-0.4.3 lib/iron_worker_ng/feature/ruby/merge_gemfile.rb
iron_worker_ng-0.4.2 lib/iron_worker_ng/feature/ruby/merge_gemfile.rb
iron_worker_ng-0.4.1 lib/iron_worker_ng/feature/ruby/merge_gemfile.rb
iron_worker_ng-0.4.0 lib/iron_worker_ng/feature/ruby/merge_gemfile.rb