Class: Thor::Actions::InjectIntoFile

Inherits:
Object
  • Object
show all
Defined in:
lib/thor/actions/inject_into_file.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, destination, data, flag, log_status = true) ⇒ InjectIntoFile

Returns a new instance of InjectIntoFile.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/thor/actions/inject_into_file.rb', line 39

def initialize(base, destination, data, flag, log_status=true)
  @base, @log_status = base, log_status
  behavior, @flag = flag.keys.first, flag.values.first

  self.destination = destination
  data = data.call if data.is_a?(Proc)

  @replacement = if behavior == :after
    @flag + data
  else
    data + @flag
  end
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



37
38
39
# File 'lib/thor/actions/inject_into_file.rb', line 37

def base
  @base
end

#destinationObject

Returns the value of attribute destination.



37
38
39
# File 'lib/thor/actions/inject_into_file.rb', line 37

def destination
  @destination
end

#flagObject (readonly)

Returns the value of attribute flag.



37
38
39
# File 'lib/thor/actions/inject_into_file.rb', line 37

def flag
  @flag
end

#relative_destinationObject (readonly)

Returns the value of attribute relative_destination.



37
38
39
# File 'lib/thor/actions/inject_into_file.rb', line 37

def relative_destination
  @relative_destination
end

#replacementObject (readonly)

Returns the value of attribute replacement.



37
38
39
# File 'lib/thor/actions/inject_into_file.rb', line 37

def replacement
  @replacement
end

Instance Method Details

#invoke!Object



53
54
55
56
# File 'lib/thor/actions/inject_into_file.rb', line 53

def invoke!
  say_status :inject
  replace!(flag, replacement)
end

#revoke!Object



58
59
60
61
# File 'lib/thor/actions/inject_into_file.rb', line 58

def revoke!
  say_status :deinject
  replace!(replacement, flag)
end