Sha256: 9ae548e0fc0937e0530862d7236dd8fa478e48fdc3ebd92d7724fd3239260a08

Contents?: true

Size: 1.36 KB

Versions: 48

Compression:

Stored size: 1.36 KB

Contents

# typed: strict
# frozen_string_literal: true

module Tapioca
  module Helpers
    module Test
      module Content
        extend T::Sig
        extend T::Helpers

        requires_ancestor { Kernel }

        sig { void }
        def teardown
          super
          remove_tmp_path
        end

        sig { params(args: String).returns(String) }
        def tmp_path(*args)
          @tmp_path = T.let(@tmp_path, T.nilable(String))
          @tmp_path ||= Dir.mktmpdir
          T.unsafe(File).join(@tmp_path, *args)
        end

        sig { void }
        def remove_tmp_path
          FileUtils.rm_rf(tmp_path)
        end

        sig { params(name: String, content: String, require_file: T::Boolean).returns(String) }
        def add_ruby_file(name, content, require_file: true)
          add_content_file(name, content).tap do |file_name|
            Tapioca.silence_warnings { require(file_name) } if require_file
          end
        end

        sig { params(name: String, content: String).returns(String) }
        def add_content_file(name, content)
          file_name = tmp_path("lib/#{name}")
          raise ArgumentError, "a file named '#{name}' was already added; cannot overwrite." if File.exist?(file_name)

          FileUtils.mkdir_p(File.dirname(file_name))
          File.write(file_name, content)
          file_name
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
tapioca-0.16.8 lib/tapioca/helpers/test/content.rb
tapioca-0.16.7 lib/tapioca/helpers/test/content.rb
tapioca-0.16.6 lib/tapioca/helpers/test/content.rb
tapioca-0.16.5 lib/tapioca/helpers/test/content.rb
tapioca-0.16.4 lib/tapioca/helpers/test/content.rb
tapioca-0.16.3 lib/tapioca/helpers/test/content.rb
tapioca-0.16.2 lib/tapioca/helpers/test/content.rb
tapioca-0.16.1 lib/tapioca/helpers/test/content.rb
tapioca-0.16.0 lib/tapioca/helpers/test/content.rb
tapioca-0.15.1 lib/tapioca/helpers/test/content.rb
tapioca-0.15.0 lib/tapioca/helpers/test/content.rb
tapioca-0.14.4 lib/tapioca/helpers/test/content.rb
tapioca-0.14.3 lib/tapioca/helpers/test/content.rb
tapioca-0.13.3 lib/tapioca/helpers/test/content.rb
tapioca-0.13.2 lib/tapioca/helpers/test/content.rb
tapioca-0.13.1 lib/tapioca/helpers/test/content.rb
tapioca-0.13.0 lib/tapioca/helpers/test/content.rb
tapioca-0.12.0 lib/tapioca/helpers/test/content.rb
tapioca-0.11.17 lib/tapioca/helpers/test/content.rb
tapioca-0.11.16 lib/tapioca/helpers/test/content.rb