Class: Progress::WithProgress
- Inherits:
-
Object
- Object
- Progress::WithProgress
- Defined in:
- lib/progress/with_progress.rb
Overview
Handling with_progress
Instance Attribute Summary collapse
-
#enum ⇒ Object
(also: #enumerable)
readonly
Returns the value of attribute enum.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.new(*args, &block) ⇒ Object
If block given run each on instance otherwise return instance.
Instance Method Summary collapse
-
#in_threads(*args, &block) ⇒ Object
befriend with in_threads gem.
-
#initialize(enum, title = nil, length = nil) ⇒ 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?(method, include_private = false) ⇒ Boolean
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
-
#with_progress(title = nil, length = nil, &block) ⇒ Object
returns self but changes title.
Constructor Details
#initialize(enum, title = nil, length = nil) ⇒ WithProgress
initialize with object responding to each, title and optional length if block is provided, it is passed to each
17 18 19 |
# File 'lib/progress/with_progress.rb', line 17 def initialize(enum, title = nil, length = nil) @enum, @title, @length = enum, title, length end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/progress/with_progress.rb', line 43 def method_missing(method, *args, &block) if enumerable_method?(method) run(method, *args, &block) else super end end |
Instance Attribute Details
#enum ⇒ Object (readonly) Also known as: enumerable
Returns the value of attribute enum.
7 8 9 |
# File 'lib/progress/with_progress.rb', line 7 def enum @enum end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/progress/with_progress.rb', line 7 def title @title end |
Class Method Details
.new(*args, &block) ⇒ Object
If block given run each on instance otherwise return instance
11 12 13 |
# File 'lib/progress/with_progress.rb', line 11 def self.new(*args, &block) block ? super.each(&block) : super end |
Instance Method Details
#in_threads(*args, &block) ⇒ Object
befriend with in_threads gem
27 28 29 30 31 |
# File 'lib/progress/with_progress.rb', line 27 def in_threads(*args, &block) @enum.in_threads(*args).with_progress(@title, @length, &block) rescue NoMethodError super end |
#respond_to?(method, include_private = false) ⇒ Boolean
38 39 40 |
# File 'lib/progress/with_progress.rb', line 38 def respond_to?(method, include_private = false) enumerable_method?(method) || super end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
33 34 35 |
# File 'lib/progress/with_progress.rb', line 33 def respond_to_missing?(method, include_private = false) enumerable_method?(method) || super end |
#with_progress(title = nil, length = nil, &block) ⇒ Object
returns self but changes title
22 23 24 |
# File 'lib/progress/with_progress.rb', line 22 def with_progress(title = nil, length = nil, &block) self.class.new(@enum, title, length || @length, &block) end |