Class: Pineapples::Actions::CreateFile
- Inherits:
-
EmptyDirectory
- Object
- Action
- EmptyDirectory
- Pineapples::Actions::CreateFile
- Defined in:
- lib/pineapples/actions/create_file.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Action
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Attributes inherited from EmptyDirectory
Attributes inherited from Action
Instance Method Summary collapse
- #identical? ⇒ Boolean
-
#initialize(generator, target, content, options = {}) ⇒ CreateFile
constructor
A new instance of CreateFile.
- #invoke! ⇒ Object
- #render ⇒ Object
Methods inherited from EmptyDirectory
Methods inherited from Action
colors, inherited, #skip?, status_color
Constructor Details
#initialize(generator, target, content, options = {}) ⇒ CreateFile
Returns a new instance of CreateFile.
63 64 65 66 |
# File 'lib/pineapples/actions/create_file.rb', line 63 def initialize(generator, target, content, = {}) super(generator, target, ) @content = content end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
56 57 58 |
# File 'lib/pineapples/actions/create_file.rb', line 56 def content @content end |
Instance Method Details
#identical? ⇒ Boolean
68 69 70 |
# File 'lib/pineapples/actions/create_file.rb', line 68 def identical? exists? && File.binread(target.fullpath) == render end |
#invoke! ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/pineapples/actions/create_file.rb', line 76 def invoke! invoke_with_conflict_check do FileUtils.mkdir_p(File.dirname(target.fullpath)) File.open(target.fullpath, 'wb') { |file| file.write render } end target.given end |
#render ⇒ Object
72 73 74 |
# File 'lib/pineapples/actions/create_file.rb', line 72 def render @render ||= content.is_a?(Proc) ? content.call : content.to_s end |