Sha256: 2bc1194a375ccc1178a128e0a573857928296634257aa9d49b3f3083771eb757

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require 'eac_rails_gem_support/patches/object/template'
require 'eac_ruby_gems_utils/gem'
require 'eac_ruby_utils/core_ext'
require 'fileutils'

module EacRailsGemSupport
  module Rspec
    class AppendableRailsApp
      enable_simple_cache
      common_constructor :gem_dir, :append_dir, :target_dir, default: [nil] do
        self.target_dir = ::EacRubyUtils::Fs::ClearableDirectory.new(
          (target_dir || ::Dir.mktmpdir).to_pathname
        )
        build
      end

      protected

      def build
        clear_target
        copy_app_base
        copy_append_directory
        database_migrate
      end

      def database_migrate
        the_gem.bundle('exec', 'rake', 'db:migrate').chdir_root.execute!
      end

      def clear_target
        target_dir.clear
      end

      def copy_app_base
        template.apply(self, target_dir)
      end

      def copy_append_directory
        ::FileUtils.cp_r("#{append_dir}/.", target_dir)
      end

      def the_gem_uncached
        ::EacRubyGemsUtils::Gem.new(target_dir)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eac_rails_gem_support-0.4.0 lib/eac_rails_gem_support/rspec/appendable_rails_app.rb
eac_rails_gem_support-0.3.0 lib/eac_rails_gem_support/rspec/appendable_rails_app.rb