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.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#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(base, relative_path, content, context: nil, force: false, skip: false, verbose: true, noop: false, color: :green, quiet: true) ⇒ CreateFile
constructor
A new instance of CreateFile.
Constructor Details
#initialize(base, relative_path, content, context: nil, force: false, skip: false, verbose: true, noop: false, color: :green, quiet: true) ⇒ CreateFile
Returns a new instance of CreateFile.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tty/file/create_file.rb', line 11 def initialize(base, relative_path, content, context: nil, force: false, skip: false, verbose: true, noop: false, color: :green, quiet: true) @base = base @content = content @context = context || @base @force = force @skip = skip @noop = noop @verbose = verbose @color = color @relative_path = convert_encoded_path(relative_path) @prompt = TTY::Prompt.new(quiet: quiet) end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
9 10 11 |
# File 'lib/tty/file/create_file.rb', line 9 def base @base end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
9 10 11 |
# File 'lib/tty/file/create_file.rb', line 9 def content @content end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/tty/file/create_file.rb', line 9 def context @context end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
9 10 11 |
# File 'lib/tty/file/create_file.rb', line 9 def prompt @prompt end |
#relative_path ⇒ Object (readonly)
Returns the value of attribute relative_path.
9 10 11 |
# File 'lib/tty/file/create_file.rb', line 9 def relative_path @relative_path end |
Instance Method Details
#call ⇒ Object
Create a file
37 38 39 40 41 42 43 |
# File 'lib/tty/file/create_file.rb', line 37 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
26 27 28 |
# File 'lib/tty/file/create_file.rb', line 26 def exist? ::File.exist?(relative_path) end |
#identical? ⇒ Boolean
30 31 32 |
# File 'lib/tty/file/create_file.rb', line 30 def identical? ::File.binread(relative_path) == content end |