Module: Tapioca::Helpers::Test::Content
Overview
@requires_ancestor: Kernel
Instance Method Summary collapse
-
#add_content_file(name, content) ⇒ Object
: (String name, String content) -> String.
-
#add_ruby_file(name, content, require_file: true) ⇒ Object
: (String name, String content, ?require_file: bool) -> String.
-
#remove_tmp_path ⇒ Object
: -> void.
-
#teardown ⇒ Object
: -> void.
-
#tmp_path(*args) ⇒ Object
: (*String args) -> String.
Instance Method Details
#add_content_file(name, content) ⇒ Object
: (String name, String content) -> String
36 37 38 39 40 41 42 43 |
# File 'lib/tapioca/helpers/test/content.rb', line 36 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 |
#add_ruby_file(name, content, require_file: true) ⇒ Object
: (String name, String content, ?require_file: bool) -> String
29 30 31 32 33 |
# File 'lib/tapioca/helpers/test/content.rb', line 29 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 |
#remove_tmp_path ⇒ Object
: -> void
24 25 26 |
# File 'lib/tapioca/helpers/test/content.rb', line 24 def remove_tmp_path FileUtils.rm_rf(tmp_path) end |
#teardown ⇒ Object
: -> void
11 12 13 14 |
# File 'lib/tapioca/helpers/test/content.rb', line 11 def teardown super remove_tmp_path end |
#tmp_path(*args) ⇒ Object
: (*String args) -> String
17 18 19 20 21 |
# File 'lib/tapioca/helpers/test/content.rb', line 17 def tmp_path(*args) @tmp_path = @tmp_path #: String? @tmp_path ||= Dir.mktmpdir T.unsafe(File).join(@tmp_path, *args) end |