Class: Caffeinate::DripperCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/caffeinate/dripper_collection.rb

Instance Method Summary collapse

Constructor Details

#initializeDripperCollection

Returns a new instance of DripperCollection.



7
8
9
# File 'lib/caffeinate/dripper_collection.rb', line 7

def initialize
  @registry = {}
end

Instance Method Details

#clear!Object



32
33
34
# File 'lib/caffeinate/dripper_collection.rb', line 32

def clear!
  @registry = {}
end

#clear_cache!Object

Caffeinate maintains a couple of class-variables under the hood that don’t get reset between specs (while the db records they cache do get truncated). This resets the appropriate class-variables between specs



26
27
28
29
30
# File 'lib/caffeinate/dripper_collection.rb', line 26

def clear_cache!
  drippers.each do |dripper|
    dripper.safe_constantize.class_eval { @caffeinate_campaign = nil }
  end
end

#drippersObject



19
20
21
# File 'lib/caffeinate/dripper_collection.rb', line 19

def drippers
  @registry.values
end

#register(name, klass) ⇒ Object



11
12
13
# File 'lib/caffeinate/dripper_collection.rb', line 11

def register(name, klass)
  @registry[name.to_sym] = klass
end

#resolve(campaign) ⇒ Object



15
16
17
# File 'lib/caffeinate/dripper_collection.rb', line 15

def resolve(campaign)
  @registry[campaign.slug.to_sym].constantize
end