Class: Replicate::Status
- Inherits:
-
Object
- Object
- Replicate::Status
- Defined in:
- lib/replicate/status.rb
Overview
Replicate filter that writes info to the console. Used by the Dumper and Loader to get basic console output.
Instance Method Summary collapse
- #call(type, id, attrs, object) ⇒ Object
- #complete ⇒ Object
- #dump_stats(stats = @dumper.stats.dup) ⇒ Object
- #format_class_name(class_name) ⇒ Object
-
#initialize(dumper, prefix, out, verbose = false, quiet = false) ⇒ Status
constructor
A new instance of Status.
- #normal_log(type, id, attrs, object) ⇒ Object
- #verbose_log(type, id, attrs, object) ⇒ Object
Constructor Details
#initialize(dumper, prefix, out, verbose = false, quiet = false) ⇒ Status
Returns a new instance of Status.
5 6 7 8 9 10 11 12 |
# File 'lib/replicate/status.rb', line 5 def initialize(dumper, prefix, out, verbose=false, quiet=false) @dumper = dumper @prefix = prefix @out = out @verbose = verbose @quiet = quiet @count = 0 end |
Instance Method Details
#call(type, id, attrs, object) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/replicate/status.rb', line 14 def call(type, id, attrs, object) @count += 1 if @verbose verbose_log type, id, attrs, object elsif !@quiet normal_log type, id, attrs, object end end |
#complete ⇒ Object
33 34 35 |
# File 'lib/replicate/status.rb', line 33 def complete dump_stats if !@quiet end |
#dump_stats(stats = @dumper.stats.dup) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/replicate/status.rb', line 37 def dump_stats(stats=@dumper.stats.dup) @out.puts "==> #{@prefix}ed #{@count} total objects: " width = 0 stats.keys.each do |key| class_name = format_class_name(key) stats[class_name] = stats.delete(key) width = class_name.size if class_name.size > width end stats.to_a.sort_by { |k,n| k }.each do |class_name, count| @out.write "%-#{width + 1}s %5d\n" % [class_name, count] end end |
#format_class_name(class_name) ⇒ Object
50 51 52 |
# File 'lib/replicate/status.rb', line 50 def format_class_name(class_name) class_name.sub(/Replicate::/, '') end |
#normal_log(type, id, attrs, object) ⇒ Object
29 30 31 |
# File 'lib/replicate/status.rb', line 29 def normal_log(type, id, attrs, object) @out.write "==> #{@prefix}ing: #{@count} objects \r" end |
#verbose_log(type, id, attrs, object) ⇒ Object
23 24 25 26 27 |
# File 'lib/replicate/status.rb', line 23 def verbose_log(type, id, attrs, object) desc_attr = %w[name login email number title].find { |k| attrs.key?(k) } desc = desc_attr ? attrs[desc_attr] : id @out.puts "#{@prefix}: %-30s %s" % [type.sub('Replicate::', ''), desc] end |