Module: CommandExtension::AfterCommit::InstanceMethods

Defined in:
lib/command_extension/after_commit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#after_commit_queue_enabledObject



28
29
30
31
# File 'lib/command_extension/after_commit.rb', line 28

def after_commit_queue_enabled
  @after_commit_queue_enabled = true if @after_commit_queue_enabled.nil?
  @after_commit_queue_enabled
end

Instance Method Details

#after_commit(method = nil, &block) ⇒ Object



22
23
24
25
26
# File 'lib/command_extension/after_commit.rb', line 22

def after_commit(method = nil, &block)
  after_commit_queue << proc { send(method) } if method
  after_commit_queue << block if block
  true
end

#after_commit_queueObject



13
14
15
# File 'lib/command_extension/after_commit.rb', line 13

def after_commit_queue
  @after_commit_queue ||= []
end

#after_commit_queue_enabled?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/command_extension/after_commit.rb', line 33

def after_commit_queue_enabled?
  after_commit_queue_enabled
end

#executeObject



37
38
39
40
# File 'lib/command_extension/after_commit.rb', line 37

def execute
  run_after_commit_queue if after_commit_queue_enabled?
  super
end

#resetObject



17
18
19
20
# File 'lib/command_extension/after_commit.rb', line 17

def reset
  @after_commit_queue = nil
  super
end

#run_after_commit_queueObject



50
51
52
53
# File 'lib/command_extension/after_commit.rb', line 50

def run_after_commit_queue
  self.class.run_after_commit_queue(self)
  after_commit_queue.each(&:call)
end

#subcommand(command) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/command_extension/after_commit.rb', line 42

def subcommand(command)
  command.after_commit_queue_enabled = false
  after_commit do
    command.run_after_commit_queue
  end
  command
end