Class: Decidim::SpamSignal::Scans::ScansRepository

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/decidim/spam_signal/scans/scans_repository.rb

Overview

Strategies repository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScansRepository

Returns a new instance of ScansRepository.



14
15
16
# File 'lib/decidim/spam_signal/scans/scans_repository.rb', line 14

def initialize
  @_strategies = {}
end

Instance Attribute Details

#strategiesObject (readonly)

Returns the value of attribute strategies.



12
13
14
# File 'lib/decidim/spam_signal/scans/scans_repository.rb', line 12

def strategies
  @strategies
end

Instance Method Details

#form_for(strategy) ⇒ Object



32
33
34
# File 'lib/decidim/spam_signal/scans/scans_repository.rb', line 32

def form_for(strategy)
  strategy(strategy).form
end

#register(strategy, command_klass) ⇒ Object



18
19
20
# File 'lib/decidim/spam_signal/scans/scans_repository.rb', line 18

def register(strategy, command_klass)
  @_strategies[strategy.to_sym] = command_klass
end

#strategy(strategy) ⇒ Object



36
37
38
39
40
# File 'lib/decidim/spam_signal/scans/scans_repository.rb', line 36

def strategy(strategy)
  key = "#{strategy}".to_sym
  return @_strategies[key] if @_strategies.key? key
  nil
end

#unset_strategy(strategy) ⇒ Object

Raises:



22
23
24
25
26
# File 'lib/decidim/spam_signal/scans/scans_repository.rb', line 22

def unset_strategy(strategy)
  key = strategy.to_sym
  raise Error, "Cop's Strategy #{strategy} does not exists" unless @_strategies.key? key
  @_strategies.except!(key)
end