Class: TTY::File::CreateFile
- Inherits:
-
Object
- Object
- TTY::File::CreateFile
- Defined in:
- lib/tty/file/create_file.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
-
#relative_path ⇒ Object
readonly
Returns the value of attribute relative_path.
Instance Method Summary collapse
-
#call ⇒ Object
Create a file.
- #exist? ⇒ Boolean
- #identical? ⇒ Boolean
-
#initialize(relative_path, content, options = {}) ⇒ CreateFile
constructor
A new instance of CreateFile.
- #log_status(*args) ⇒ Object
Constructor Details
#initialize(relative_path, content, options = {}) ⇒ CreateFile
Returns a new instance of CreateFile.
8 9 10 11 12 13 |
# File 'lib/tty/file/create_file.rb', line 8 def initialize(relative_path, content, = {}) @content = content = @relative_path = convert_encoded_path(relative_path) @prompt = TTY::Prompt.new end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
6 7 8 |
# File 'lib/tty/file/create_file.rb', line 6 def content @content end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/tty/file/create_file.rb', line 6 def end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
6 7 8 |
# File 'lib/tty/file/create_file.rb', line 6 def prompt @prompt end |
#relative_path ⇒ Object (readonly)
Returns the value of attribute relative_path.
6 7 8 |
# File 'lib/tty/file/create_file.rb', line 6 def relative_path @relative_path end |
Instance Method Details
#call ⇒ Object
Create a file
30 31 32 33 34 35 36 |
# File 'lib/tty/file/create_file.rb', line 30 def call detect_collision do FileUtils.mkdir_p(::File.dirname(relative_path)) ::File.open(relative_path, 'wb') { |f| f.write(content) } end relative_path end |
#exist? ⇒ Boolean
15 16 17 |
# File 'lib/tty/file/create_file.rb', line 15 def exist? ::File.exist?(relative_path) end |
#identical? ⇒ Boolean
19 20 21 |
# File 'lib/tty/file/create_file.rb', line 19 def identical? ::File.binread(relative_path) == content end |
#log_status(*args) ⇒ Object
23 24 25 |
# File 'lib/tty/file/create_file.rb', line 23 def log_status(*args) TTY::File.log_status(*args) end |