Class: TTY::File::CreateFile
- Inherits:
-
Object
- Object
- TTY::File::CreateFile
- Defined in:
- lib/tty/file/create_file.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#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.
- #context ⇒ Object
- #exist? ⇒ Boolean
- #identical? ⇒ Boolean
-
#initialize(base, relative_path, content, options = {}) ⇒ CreateFile
constructor
A new instance of CreateFile.
Constructor Details
#initialize(base, relative_path, content, options = {}) ⇒ CreateFile
Returns a new instance of CreateFile.
9 10 11 12 13 14 15 |
# File 'lib/tty/file/create_file.rb', line 9 def initialize(base, relative_path, content, = {}) @base = base @content = content = @relative_path = convert_encoded_path(relative_path) @prompt = TTY::Prompt.new end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
7 8 9 |
# File 'lib/tty/file/create_file.rb', line 7 def base @base end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
7 8 9 |
# File 'lib/tty/file/create_file.rb', line 7 def content @content end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/tty/file/create_file.rb', line 7 def end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
7 8 9 |
# File 'lib/tty/file/create_file.rb', line 7 def prompt @prompt end |
#relative_path ⇒ Object (readonly)
Returns the value of attribute relative_path.
7 8 9 |
# File 'lib/tty/file/create_file.rb', line 7 def relative_path @relative_path end |
Instance Method Details
#call ⇒ Object
Create a file
32 33 34 35 36 37 38 |
# File 'lib/tty/file/create_file.rb', line 32 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 |
#context ⇒ Object
17 18 19 |
# File 'lib/tty/file/create_file.rb', line 17 def context [:context] || @base end |
#exist? ⇒ Boolean
21 22 23 |
# File 'lib/tty/file/create_file.rb', line 21 def exist? ::File.exist?(relative_path) end |
#identical? ⇒ Boolean
25 26 27 |
# File 'lib/tty/file/create_file.rb', line 25 def identical? ::File.binread(relative_path) == content end |