Class: RailsUI

Inherits:
BaseUI show all
Defined in:
lib/libisi/ui/rails.rb

Instance Method Summary collapse

Methods inherited from BaseUI

#bell, #colorize, #error, #execute_in_console, #info_non_blocking, #name, #not_implemented, #pinc, #pmsg, #progress_bar, #progress_bar_enabled?, #question, #question_yes_no, #question_yes_no_retry, #select, #select_index, #warn

Instance Method Details

#enable_progress_bar(val = true, &block) ⇒ Object

PROGRESS



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/libisi/ui/rails.rb', line 26

def enable_progress_bar(val = true, &block)
  raise "Need block around progress for rails ui." unless block_given?
  params = eval("params",block.binding)
  if val and not params[:no_progress]
    @progress = true
    
    progress_name = params[:progress_name]
    
    if progress_name
	eval("@progress_name = #{progress_name.inspect}",block.binding)
	if params[:real_task]
 # now this processid will stay until
 # the task is finished, takover the file
 orig_file = progress_file(progress_name)
 new_file = progress_file(current_progress_name)
 begin
   FileUtils.mv(orig_file,new_file)
   orig_file.make_symlink(new_file)

   $progress_cache[Process.pid] = load_progress
 
   # this is the real task, go for it
   yield
   eval('render :layout => false', block.binding)
 ensure
   orig_file.delete if orig_file.exist?
   new_file.delete if new_file.exist?
   $progress_cache[Process.pid] = nil
 end
	else
 # this is the progressbar call, render it
 eval('render :layout => false, :action => "../application/progress_bar"', block.binding)
	end
    else
	# this is the initialization step
	# create a new id for the progressbar
	# this name must be able to be an id of a html tag
	progress_name = current_progress_name
	# make it unique
	progress_name += "#{Time.now.to_i}"
	eval("@progress_name = #{progress_name.inspect}",block.binding)
	
	$progress_cache[Process.pid] = {}
	save_progress(progress_name)
	$progress_cache[Process.pid] = nil
	
	# render a page with progressbar
	# and a content for the main page
	eval('render :action => "../application/progress_page"', block.binding)
    end
  else
    @progress = false
    yield
  end
  @progress = false
end

#info(text, options = {}) ⇒ Object



21
22
23
# File 'lib/libisi/ui/rails.rb', line 21

def info(text, options = {})
  print "#{text}\n"
end

#progress(count) ⇒ Object



95
96
97
98
# File 'lib/libisi/ui/rails.rb', line 95

def progress(count)
  $progress_cache[Process.pid][:current] = count
  save_progress
end

#progress_bar_implementation(text, total, &block) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/libisi/ui/rails.rb', line 83

def progress_bar_implementation(text, total, &block)
  if progress_bar_enabled?
    $progress_cache[Process.pid] = {:count => total.to_i, :current => 0, :text => text}
    save_progress
    yield
    $progress_cache[Process.pid] = nil
    save_progress
  else
    yield
  end
end

#progress_incObject



99
100
101
102
# File 'lib/libisi/ui/rails.rb', line 99

def progress_inc
  $progress_cache[Process.pid][:current] += 1
  save_progress
end

#progress_message(text) ⇒ Object



103
104
105
106
# File 'lib/libisi/ui/rails.rb', line 103

def progress_message(text)
  $progress_cache[Process.pid][:text] = text
  save_progress
end

#progress_values(name) ⇒ Object



108
109
110
# File 'lib/libisi/ui/rails.rb', line 108

def progress_values(name)
  load_progress(name)
end