Class: Progress::WithProgress
- Inherits:
-
Object
- Object
- Progress::WithProgress
- Defined in:
- lib/progress/with_progress.rb
Instance Attribute Summary collapse
-
#enumerable ⇒ Object
readonly
Returns the value of attribute enumerable.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#in_threads(*args, &block) ⇒ Object
befriend with in_threads gem.
-
#initialize(enumerable, title, length = nil, &block) ⇒ WithProgress
constructor
initialize with object responding to each, title and optional length if block is provided, it is passed to each.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(sym, include_private = false) ⇒ Boolean
-
#with_progress(title = nil, length = nil, &block) ⇒ Object
returns self but changes title.
Constructor Details
#initialize(enumerable, title, length = nil, &block) ⇒ WithProgress
initialize with object responding to each, title and optional length if block is provided, it is passed to each
9 10 11 12 |
# File 'lib/progress/with_progress.rb', line 9 def initialize(enumerable, title, length = nil, &block) @enumerable, @title, @length = enumerable, title, length each(&block) if block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/progress/with_progress.rb', line 30 def method_missing(method, *args, &block) if enumerable_method?(method) run(method, *args, &block) else super(method, *args, &block) end end |
Instance Attribute Details
#enumerable ⇒ Object (readonly)
Returns the value of attribute enumerable.
5 6 7 |
# File 'lib/progress/with_progress.rb', line 5 def enumerable @enumerable end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/progress/with_progress.rb', line 5 def title @title end |
Instance Method Details
#in_threads(*args, &block) ⇒ Object
befriend with in_threads gem
20 21 22 23 24 |
# File 'lib/progress/with_progress.rb', line 20 def in_threads(*args, &block) @enumerable.in_threads(*args).with_progress(@title, @length, &block) rescue super end |
#respond_to?(sym, include_private = false) ⇒ Boolean
26 27 28 |
# File 'lib/progress/with_progress.rb', line 26 def respond_to?(sym, include_private = false) enumerable_method?(method) || super(sym, include_private) end |
#with_progress(title = nil, length = nil, &block) ⇒ Object
returns self but changes title
15 16 17 |
# File 'lib/progress/with_progress.rb', line 15 def with_progress(title = nil, length = nil, &block) self.class.new(@enumerable, title, length || @length, &block) end |