Sha256: 087387d97baf463449eb91e021eb3657c80be56a1cd05fc646a32be7587b5f93

Contents?: true

Size: 1.32 KB

Versions: 29

Compression:

Stored size: 1.32 KB

Contents

require 'thor'
require 'eucalypt/errors'

module Eucalypt
  module Helpers
    module Gemfile
      def gemfile_add(description, gems, directory)
        gemfile = File.join(directory, 'Gemfile')
        File.open gemfile do |f|
          includes_gems = []
          contents = f.read
          gems.each do |gem, _|
            includes_gems << true if contents.include? "gem '#{gem}'"
          end
          return unless includes_gems.empty?
        end

        append_to_file gemfile, "\n# #{description}\n"
        gems.each_with_index do |gemdata, i|
          gem, version = gemdata
          gem_string = "gem '#{gem}', '#{version}'" << (i==gems.size-1 ? '' : "\n")
          append_to_file gemfile, gem_string
        end
      end

      class << self
        def include?(gems, directory)
          includes_gems = []
          gemfile = File.join(directory, 'Gemfile')
          File.open gemfile do |f|
            contents = f.read
            gems.each {|gem| includes_gems << contents.include?("gem '#{gem}'") }
          end
          includes_gems.all? {|present| present == true}
        end

        def check(gems, command, directory)
          if include?(gems, directory)
            true
          else
            Eucalypt::Error.no_gems(gems, command)
            false
          end
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
eucalypt-0.9.0 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.8.0 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.7.2 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.7.1 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.7.0 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.6.2 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.6.1 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.6.0 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.5.4 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.5.3 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.5.2 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.5.1 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.5.0 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.4.2 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.4.1 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.4.0 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.3.5 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.3.4 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.3.3 lib/eucalypt/helpers/gemfile.rb
eucalypt-0.3.2 lib/eucalypt/helpers/gemfile.rb