Sha256: 690f7b97c7cc9883b92ac2d5a2c1ff7985e119f7b133143b49d44af7780a75f6

Contents?: true

Size: 1006 Bytes

Versions: 30

Compression:

Stored size: 1006 Bytes

Contents

module Merit
  class TargetFinder < Struct.new(:rule, :action)
    def self.find(*args)
      new(*args).find
    end

    def find
      target = case rule.to
               when :itself then
                 base_target
               when :action_user then
                 action_user
               else
                 other_target
               end
      Array.wrap(target)
    end

    private

    def base_target
      BaseTargetFinder.find rule, action
    end

    def action_user
      user = Merit.user_model.find_by_id action.user_id
      if user.nil?
        user_model = Merit.user_model
        str = "[merit] no #{user_model} found with id #{action.user_id}"
        Rails.logger.warn str
      end
      user
    end

    def other_target
      base_target.send rule.to
    rescue NoMethodError
      str = "[merit] NoMethodError on `#{base_target.class.name}##{rule.to}`" \
            ' (called from Merit::TargetFinder#other_target)'
      Rails.logger.warn str
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

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