Module: Sp2db::ImportStrategy
Defined Under Namespace
Classes: Base
Instance Method Summary collapse
-
#add(label, strategy = nil, &block) ⇒ Object
Add strategy.
- #labels ⇒ Object
- #strategies ⇒ Object
- #strategy_by_name(name) ⇒ Object
- #valid!(s) ⇒ Object
Instance Method Details
#add(label, strategy = nil, &block) ⇒ Object
Add strategy
7 8 9 10 11 |
# File 'lib/sp2db/import_strategy.rb', line 7 def add label, strategy=nil, &block strategy ||= Class.new(Base) strategy.class_eval(&block) if block_given? strategies[label.to_sym] = strategy end |
#labels ⇒ Object
22 23 24 |
# File 'lib/sp2db/import_strategy.rb', line 22 def labels strategies.keys.map(&:to_sym) end |
#strategies ⇒ Object
14 15 16 |
# File 'lib/sp2db/import_strategy.rb', line 14 def strategies @strategies ||= {}.with_indifferent_access end |
#strategy_by_name(name) ⇒ Object
18 19 20 |
# File 'lib/sp2db/import_strategy.rb', line 18 def strategy_by_name name strategies[name.to_s] || raise("Invalid import strategy: #{name}") end |
#valid!(s) ⇒ Object
26 27 28 29 |
# File 'lib/sp2db/import_strategy.rb', line 26 def valid! s raise "Unsuported strategies" unless labels.include?(s.to_sym) true end |