Sha256: bffab5bc165a9b62e645db6e4359f6f1b3eb9ca871a683be150d81ed1f722499

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 KB

Contents

module Vx
  module Builder
    class ScriptBuilder

      class Ruby < Base

        DEFAULT_RUBY = '1.9.3'

        def call(env)
          if enabled?(env)

            vxvm_install(env, 'ruby', ruby_version(env))

            do_cache_key(env) do |i|
              i << "rvm-#{ruby_version env}"
              i << gemfile(env)
            end

            do_before_install(env) do |i|
              i << trace_sh_command("export BUNDLE_GEMFILE=${PWD}/#{gemfile(env)}")
              i << trace_sh_command('export GEM_HOME=~/.rubygems')
            end

            do_announce(env) do |i|
              i << trace_sh_command("ruby --version")
              i << trace_sh_command("gem --version")
              i << trace_sh_command("bundle --version")
            end

            do_install(env) do |i|
              bundler_args = env.source.bundler_args.first
              i << trace_sh_command("bundle install #{bundler_args}")
              i << trace_sh_command("bundle clean --force")
            end

            do_script(env) do |i|
              script = "if [ -f Rakefile ] ; then \n #{trace_sh_command "bundle exec rake"}\nfi"
              i << script
            end

            do_cached_directories(env) do |i|
              i << "~/.rubygems"
            end
          end

          app.call(env)
        end

        private

          def enabled?(env)
            env.source.rvm.first || env.source.language == 'ruby'
          end

          def ruby_version(env)
            env.source.rvm.first || DEFAULT_RUBY
          end

          def gemfile(env)
            env.source.gemfile.first || "Gemfile"
          end

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vx-builder-0.5.4 lib/vx/builder/script_builder/ruby.rb
vx-builder-0.5.3 lib/vx/builder/script_builder/ruby.rb
vx-builder-0.5.2 lib/vx/builder/script_builder/ruby.rb
vx-builder-0.5.1 lib/vx/builder/script_builder/ruby.rb
vx-builder-0.5.0 lib/vx/builder/script_builder/ruby.rb