Class: Thor::Actions::InjectIntoFile
- Inherits:
-
EmptyDirectory
- Object
- EmptyDirectory
- Thor::Actions::InjectIntoFile
- Defined in:
- lib/thor/actions/inject_into_file.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#flag ⇒ Object
readonly
Returns the value of attribute flag.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
Attributes inherited from EmptyDirectory
#base, #config, #destination, #given_destination, #relative_destination
Instance Method Summary collapse
-
#initialize(base, destination, data, config) ⇒ InjectIntoFile
constructor
A new instance of InjectIntoFile.
- #invoke! ⇒ Object
- #revoke! ⇒ Object
Methods inherited from EmptyDirectory
Constructor Details
#initialize(base, destination, data, config) ⇒ InjectIntoFile
Returns a new instance of InjectIntoFile.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/thor/actions/inject_into_file.rb', line 40 def initialize(base, destination, data, config) super(base, destination, { :verbose => true }.merge(config)) data = data.call if data.is_a?(Proc) @replacement = if @config.key?(:after) @flag = @config.delete(:after) @flag + data else @flag = @config.delete(:before) data + @flag end end |
Instance Attribute Details
#flag ⇒ Object (readonly)
Returns the value of attribute flag.
38 39 40 |
# File 'lib/thor/actions/inject_into_file.rb', line 38 def flag @flag end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
38 39 40 |
# File 'lib/thor/actions/inject_into_file.rb', line 38 def replacement @replacement end |
Instance Method Details
#invoke! ⇒ Object
54 55 56 57 |
# File 'lib/thor/actions/inject_into_file.rb', line 54 def invoke! say_status :inject, config[:verbose] replace!(flag, replacement) end |
#revoke! ⇒ Object
59 60 61 62 |
# File 'lib/thor/actions/inject_into_file.rb', line 59 def revoke! say_status :deinject, config[:verbose] replace!(replacement, flag) end |