Class: Bundler::Thor::Actions::CreateFile
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
EmptyDirectory
|
|
|
Instance Chain:
self,
EmptyDirectory
|
|
| Inherits: |
Bundler::Thor::Actions::EmptyDirectory
|
| 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.
Class Method Summary
EmptyDirectory - Inherited
| .new | Initializes given the source and destination. |
Instance Attribute Summary
- #data readonly
-
#identical? ⇒ Boolean
readonly
Checks if the content of the file at the destination is identical to the rendered result.
-
#force_on_collision? ⇒ Boolean
readonly
protected
Shows the file collision menu to the user and gets the result.
EmptyDirectory - Inherited
| #base, #config, #destination, | |
| #exists? | Checks if the destination file already exists. |
| #given_destination, #relative_destination, | |
| #destination= | Sets the absolute destination value from a relative destination value. |
| #pretend? | Shortcut for pretend. |
Instance Method Summary
- #invoke!
-
#render
Holds the content to be added to the file.
-
#force_or_skip_or_conflict(force, skip, &block)
protected
If force is true, run the action, otherwise check if it’s not being skipped.
-
#on_conflict_behavior(&block)
protected
Now on conflict we check if the file is identical or not.
EmptyDirectory - Inherited
| #invoke!, #revoke!, | |
| #convert_encoded_instructions | Filenames in the encoded form are converted. |
| #invoke_with_conflict_check | Receives a hash of options and just execute the block if some conditions are met. |
| #on_conflict_behavior | What to do when the destination file already exists. |
| #on_file_clash_behavior, | |
| #say_status | Shortcut to say_status shell method. |
Constructor Details
.new(base, destination, data, config = {}) ⇒ CreateFile
# 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 (readonly)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/actions/create_file.rb', line 33
attr_reader :data
#force_on_collision? ⇒ Boolean (readonly, protected)
Shows the file collision menu to the user and gets the result.
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_file.rb', line 100
def force_on_collision? base.shell.file_collision(destination) { render } end
#identical? ⇒ Boolean (readonly)
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.
Instance Method Details
#force_or_skip_or_conflict(force, skip, &block) (protected)
If force is true, run the action, otherwise check if it’s not being skipped. If both are false, show the file_collision menu, if the menu returns true, force it, otherwise skip.
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_file.rb', line 86
def force_or_skip_or_conflict(force, skip, &block) if force say_status :force, :yellow yield unless pretend? elsif skip say_status :skip, :yellow else say_status :conflict, :red force_or_skip_or_conflict(force_on_collision?, true, &block) end end
#invoke!
[ GitHub ]#on_conflict_behavior(&block) (protected)
Now on conflict we check if the file is identical or not.
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_file.rb', line 73
def on_conflict_behavior(&block) if identical? say_status :identical, :blue else = base..merge(config) force_or_skip_or_conflict([:force], [:skip], &block) end end
#render
Holds the content to be added to the file.