Class: Bundler::Thor::Actions::CreateFile
- Inherits:
-
EmptyDirectory
- Object
- EmptyDirectory
- Bundler::Thor::Actions::CreateFile
- Defined in:
- lib/bundler/vendor/thor/lib/thor/actions/create_file.rb
Overview
CreateFile is a subset of Template, which instead of rendering a file with ERB, it gets the content from the user.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
:nodoc:.
Attributes inherited from EmptyDirectory
#base, #config, #destination, #given_destination, #relative_destination
Instance Method Summary collapse
-
#identical? ⇒ Boolean
Checks if the content of the file at the destination is identical to the rendered result.
-
#initialize(base, destination, data, config = {}) ⇒ CreateFile
constructor
A new instance of CreateFile.
- #invoke! ⇒ Object
-
#render ⇒ Object
Holds the content to be added to the file.
Methods inherited from EmptyDirectory
Constructor Details
#initialize(base, destination, data, config = {}) ⇒ CreateFile
Returns a new instance of CreateFile.
35 36 37 38 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_file.rb', line 35 def initialize(base, destination, data, config = {}) @data = data super(base, destination, config) end |
Instance Attribute Details
#data ⇒ Object (readonly)
:nodoc:
33 34 35 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_file.rb', line 33 def data @data end |
Instance Method Details
#identical? ⇒ Boolean
Checks if the content of the file at the destination is identical to the rendered result.
Returns
- Boolean
-
true if it is identical, false otherwise.
45 46 47 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_file.rb', line 45 def identical? exists? && File.binread(destination) == render end |
#invoke! ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_file.rb', line 59 def invoke! invoke_with_conflict_check do FileUtils.mkdir_p(File.dirname(destination)) File.open(destination, "wb") { |f| f.write render } end given_destination end |
#render ⇒ Object
Holds the content to be added to the file.
51 52 53 54 55 56 57 |
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_file.rb', line 51 def render @render ||= if data.is_a?(Proc) data.call else data end end |