Module: AutomateEm::Status

Includes:
Observable
Included in:
Logic, ModuleCore
Defined in:
lib/automate-em/status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#statusObject (readonly)

Should not be accessed like this for modification



27
28
29
# File 'lib/automate-em/status.rb', line 27

def status
  @status
end

Instance Method Details

#[](status) ⇒ Object



7
8
9
10
11
12
# File 'lib/automate-em/status.rb', line 7

def [] (status)
	status = status.to_sym if status.class == String
	@status_lock.synchronize {
		return @status[status]
	}
end

#[]=(status, data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/automate-em/status.rb', line 14

def []= (status, data)
	status = status.to_sym if status.class == String
	old_data = check_for_emit(status, data)
	
	if data != old_data
		changed								# so that the notify is applied
		logger.debug "#{self.class} status updated: #{status} = #{data}"
	end
	
	
	notify_observers(self, status, data)	# only notify changes
end

#mark_emit_endObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/automate-em/status.rb', line 36

def mark_emit_end
	@status_lock.synchronize {
		@emit_hasnt_occured.each_pair do | key, block |
			data = @status[key]
			task do
				begin
					block.call(data)
				ensure
					ActiveRecord::Base.clear_active_connections!
				end
			end
			logger.debug "A forced emit on #{status} occured"
		end
		
		@emit_hasnt_occured = nil
	}
end

#mark_emit_start(status) ⇒ Object



30
31
32
33
34
# File 'lib/automate-em/status.rb', line 30

def mark_emit_start(status)
	@status_lock.synchronize {
		@emit_hasnt_occured = status
	}
end