Class: Merit::BaseTargetFinder
- Inherits:
-
Object
- Object
- Merit::BaseTargetFinder
- Defined in:
- lib/merit/base_target_finder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #find ⇒ Object
- #get_target_from_database ⇒ Object
-
#initialize(rule, action) ⇒ BaseTargetFinder
constructor
A new instance of BaseTargetFinder.
- #model_class ⇒ Object
- #reanimate_target_from_action ⇒ Object
Constructor Details
#initialize(rule, action) ⇒ BaseTargetFinder
Returns a new instance of BaseTargetFinder.
7 8 9 10 |
# File 'lib/merit/base_target_finder.rb', line 7 def initialize(rule, action) @rule = rule @action = action end |
Class Method Details
.find(*args) ⇒ Object
3 4 5 |
# File 'lib/merit/base_target_finder.rb', line 3 def self.find(*args) new(*args).find end |
Instance Method Details
#find ⇒ Object
12 13 14 15 16 |
# File 'lib/merit/base_target_finder.rb', line 12 def find get_target_from_database || reanimate_target_from_action rescue => e Rails.logger.warn "[merit] no target found: #{e}. #{caller.first}" end |
#get_target_from_database ⇒ Object
18 19 20 |
# File 'lib/merit/base_target_finder.rb', line 18 def get_target_from_database model_class.find_by_id(@action.target_id) end |
#model_class ⇒ Object
22 23 24 25 |
# File 'lib/merit/base_target_finder.rb', line 22 def model_class klass_name = (@rule.model_name || @action.target_model).singularize klass_name.camelize.constantize end |
#reanimate_target_from_action ⇒ Object
27 28 29 |
# File 'lib/merit/base_target_finder.rb', line 27 def reanimate_target_from_action YAML.load(@action.target_data) end |