Sha256: 08647e968eb2e60f61c5db459e5b9bd6a7140c77e343e51c58535273ebc90bb0

Contents?: true

Size: 675 Bytes

Versions: 19

Compression:

Stored size: 675 Bytes

Contents

module Merit
  class BaseTargetFinder
    def self.find(*args)
      new(*args).find
    end

    def initialize(rule, action)
      @rule = rule
      @action = action
    end

    def find
      get_target_from_database || reanimate_target_from_action
    rescue => e
      Rails.logger.warn "[merit] no target found: #{e}. #{caller.first}"
    end

    def get_target_from_database
      model_class.find_by_id(@action.target_id)
    end

    def model_class
      klass_name = (@rule.model_name || @action.target_model).singularize
      klass_name.camelize.constantize
    end

    def reanimate_target_from_action
      YAML.load(@action.target_data)
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
merit-4.0.3 lib/merit/base_target_finder.rb
qalam_merit-4.5.12 lib/merit/base_target_finder.rb
merit-4.0.2 lib/merit/base_target_finder.rb
qalam_merit-4.5.11 lib/merit/base_target_finder.rb
qalam_merit-4.5.10 lib/merit/base_target_finder.rb
qalam_merit-4.5.09 lib/merit/base_target_finder.rb
qalam_merit-4.5.08 lib/merit/base_target_finder.rb
qalam_merit-4.5.07 lib/merit/base_target_finder.rb
qalam_merit-4.5.06 lib/merit/base_target_finder.rb
qalam_merit-4.5.05 lib/merit/base_target_finder.rb
qalam_merit-4.5.04 lib/merit/base_target_finder.rb
qalam_merit-4.5.03 lib/merit/base_target_finder.rb
qalam_merit-4.5.02 lib/merit/base_target_finder.rb
qalam_merit-4.5.01 lib/merit/base_target_finder.rb
qalam_merit-4.5.00 lib/merit/base_target_finder.rb
qalam_merit-4.0.4 lib/merit/base_target_finder.rb
qalam_merit-4.0.35 lib/merit/base_target_finder.rb
merit-4.0.1 lib/merit/base_target_finder.rb
merit-4.0.0 lib/merit/base_target_finder.rb