Class: Tap::Tasks::Singleton

Inherits:
Tap::Task show all
Defined in:
lib/tap/tasks/singleton.rb

Instance Attribute Summary collapse

Attributes inherited from Tap::Task

#joins

Attributes inherited from App::Api

#app

Class Method Summary collapse

Instance Method Summary collapse

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

included

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

#cacheObject (readonly)

Returns the value of attribute cache.



17
18
19
# File 'lib/tap/tasks/singleton.rb', line 17

def cache
  @cache
end

#signatureObject (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

.cacheObject



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

#resetObject



30
31
32
# File 'lib/tap/tasks/singleton.rb', line 30

def reset
  @cache = {}
end