Class: Rake::Task

Inherits:
Object
  • Object
show all
Includes:
Bow::Memorable
Defined in:
lib/bow/rake.rb

Constant Summary collapse

ALLOWED_FLOW_RULES =
%i[run enabled revert].freeze

Instance Method Summary collapse

Methods included from Bow::Memorable

#applied?, #apply, #flush_history, #reset, #revert, #reverted?, #task_history

Instance Method Details

#add_flow_rule(rule, val) ⇒ Object



116
117
118
119
# File 'lib/bow/rake.rb', line 116

def add_flow_rule(rule, val)
  return unless ALLOWED_FLOW_RULES.include? rule
  flow[rule.to_sym] = val
end

#apply_revert_taskObject



69
70
71
72
73
74
75
76
77
# File 'lib/bow/rake.rb', line 69

def apply_revert_task
  revert_task = find_revert_task
  return if reverted? || !revert_task || revert_task.applied?
  result = revert_task.execute
  revert_task.apply if revert_task.run_once?
  revert
  flush_history
  result
end

#clearObject



79
80
81
82
# File 'lib/bow/rake.rb', line 79

def clear
  clear_flow
  orig__clear
end

#clear_flowObject



84
85
86
87
# File 'lib/bow/rake.rb', line 84

def clear_flow
  @flow = {}
  self
end

#disabled?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/bow/rake.rb', line 89

def disabled?
  !enabled?
end

#enabled?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/bow/rake.rb', line 97

def enabled?
  !!flow[:enabled]
end

#find_revert_taskObject



105
106
107
108
# File 'lib/bow/rake.rb', line 105

def find_revert_task
  return unless flow[:revert]
  application.lookup(flow[:revert], @scope)
end

#flowObject



101
102
103
# File 'lib/bow/rake.rb', line 101

def flow
  @flow ||= { enabled: true, run: :always, revert: nil }
end

#invoke_with_call_chain(task_args, invocation_chain) ⇒ Object

:nodoc:



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bow/rake.rb', line 57

def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
  if disabled?
    return unless applied?
    return apply_revert_task
  end
  return if run_once? && applied?
  result = orig__invoke_with_call_chain(task_args, invocation_chain)
  apply
  flush_history
  result
end

#orig__clearObject



54
# File 'lib/bow/rake.rb', line 54

alias orig__clear clear

#orig__invoke_with_call_chainObject



55
# File 'lib/bow/rake.rb', line 55

alias orig__invoke_with_call_chain invoke_with_call_chain

#run_once?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/bow/rake.rb', line 93

def run_once?
  flow[:run] == :once
end

#unpack_flow(init_flow) ⇒ Object

Add flow to the task.



111
112
113
114
# File 'lib/bow/rake.rb', line 111

def unpack_flow(init_flow)
  return unless init_flow
  init_flow.each { |rule, val| add_flow_rule(rule, val) }
end