Class: Tap::Tasks::Singleton
- Defined in:
- lib/tap/tasks/singleton.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
Attributes inherited from Tap::Task
Attributes inherited from App::Api
Class Method Summary collapse
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#initialize(config = {}, app = Tap::App.current) ⇒ Singleton
constructor
A new instance of Singleton.
- #reset ⇒ Object
Methods inherited from Tap::Task
#associations, #enq, #exe, #log, #on_complete, parser, #process
Methods inherited from App::Api
#associations, build, help, inherited, #inspect, parse, parse!, parser, #to_spec
Methods included from Signals
#sig, #signal, #signal?, #signals
Methods included from Signals::ModuleMethods
Constructor Details
#initialize(config = {}, app = Tap::App.current) ⇒ Singleton
Returns a new instance of Singleton.
20 21 22 23 24 |
# File 'lib/tap/tasks/singleton.rb', line 20 def initialize(config={}, app=Tap::App.current) @signature = [config.dup, app].freeze super(config, app) reset end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
17 18 19 |
# File 'lib/tap/tasks/singleton.rb', line 17 def cache @cache end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
18 19 20 |
# File 'lib/tap/tasks/singleton.rb', line 18 def signature @signature end |
Class Method Details
.cache ⇒ Object
7 8 9 |
# File 'lib/tap/tasks/singleton.rb', line 7 def cache @cache ||= {} end |
.new(*args) ⇒ Object
11 12 13 14 |
# File 'lib/tap/tasks/singleton.rb', line 11 def new(*args) obj = super cache[obj.signature] ||= obj end |
Instance Method Details
#call(input) ⇒ Object
26 27 28 |
# File 'lib/tap/tasks/singleton.rb', line 26 def call(input) cache.has_key?(input) ? cache[input] : cache[input] = super end |
#reset ⇒ Object
30 31 32 |
# File 'lib/tap/tasks/singleton.rb', line 30 def reset @cache = {} end |