Module: ActiverecordWithProgress

Defined in:
lib/activerecord_with_progress.rb,
lib/activerecord_with_progress/version.rb,
lib/activerecord_with_progress/activerecord_relation.rb

Defined Under Namespace

Modules: ActiverecordRelation

Constant Summary collapse

DEFAULT_FORMAT =

Default progress bar format (see ruby-progressbar documentation).

"\e[36m%a \e[35m%e\e[0m \e[34m[\e[1m%B\e[0;34m] %c/%C %p%%\e[0m"
VERSION =
"0.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.progress_formatObject

Set or retrieve the format string used for progress bars.



12
13
14
# File 'lib/activerecord_with_progress.rb', line 12

def progress_format
  @progress_format
end

Class Method Details

.create(options = nil) ⇒ Object

Creates a progress bar with our own default options and format, unless overrided by the options hash. Also works around Spring’s removal of IO.console for Rails apps that use Spring by setting :length.



17
18
19
20
21
22
23
24
# File 'lib/activerecord_with_progress.rb', line 17

def create(options=nil)
  opts = {
    format: progress_format,
    length: (IO.console.winsize[1] rescue nil) || ENV['columns'] || `tput cols`
  }
  opts.merge!(options) if options.is_a?(Hash)
  ProgressBar.create(opts)
end