rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
 After-run callbacks
15245
def notify(*options, &block)
      raise "Couldn't create notifications without a block" unless block_given?

      conditions = *options
      conditions = DEFAULT_NOTIFICATIONS if options.empty?

      conditions.each do |condition|
        notification = Notification.new(condition)
        notification.instance_eval(&block)

        @notifications[condition] = notification
      end
    end
986029
def create
      return false unless new_record?
      run_callbacks :save do
        run_callbacks :create do
          httparty = self.class.post(self.class.index_path, request_options.merge(:body => to_json))
          handle_save_response(httparty)
        end
      end
    end
1058425
def params
      {}.
      merge!(measurable_params).
      merge!(custom_dimensions).
      merge!(custom_metrics).
      reject {|_,v| v.nil?}
    end
315758
def create_new_spec(class_or_module, dry_run, rails_mode, file_path, spec_path)
      # These names are used in ERB template, don't delete.
      # rubocop:disable Lint/UselessAssignment
      methods_to_generate = class_or_module.method_list.select { |m| m.visibility == :public }
      c = class_or_module
      self_path = to_string_value_to_require(file_path)
      # rubocop:enable Lint/UselessAssignment

      erb = RSpecKickstarter::ERBFactory.new(@full_template).get_instance_for_new_spec(rails_mode, file_path)
      code = erb.result(binding)

      if dry_run
        puts "----- #{spec_path} -----"
        puts code
      else
        if File.exist?(spec_path)
          puts "#{spec_path} already exists."
        else
          FileUtils.mkdir_p(File.dirname(spec_path))
          File.open(spec_path, 'w') { |f| f.write(code) }
          puts "#{spec_path} created."
        end
      end
    end
821573
def [](new_size)
      if new_size.is_a? Directive
        tags.merge! new_size.tags_for_sized_directive
      else
        tags[:size] = new_size
      end

      self
    end
1144464
def initialize(self, all_options):
    
    if self.run_info:
      raise AssertionError('RunTracker.initialize must not be called multiple times.')

    # Initialize the run.

    # Select a globally unique ID for the run, that sorts by time.
    millis = int((self._run_timestamp * 1000) % 1000)
    # run_uuid is used as a part of run_id and also as a trace_id for Zipkin tracing
    run_uuid = uuid.uuid4().hex
    run_id = 'pants_run_{}_{}_{}'.format(
      time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime(self._run_timestamp)),
      millis,
      run_uuid
    )

    info_dir = os.path.join(self.get_options().pants_workdir, self.options_scope)
    self.run_info_dir = os.path.join(info_dir, run_id)
    self.run_info = RunInfo(os.path.join(self.run_info_dir, 'info'))
    self.run_info.add_basic_info(run_id, self._run_timestamp)
    self.run_info.add_info('cmd_line', self._cmd_line)

    # Create a 'latest' symlink, after we add_infos, so we're guaranteed that the file exists.
    link_to_latest = os.path.join(os.path.dirname(self.run_info_dir), 'latest')

    relative_symlink(self.run_info_dir, link_to_latest)

    # Time spent in a workunit, including its children.
    self.cumulative_timings = AggregatedTimings(os.path.join(self.run_info_dir,
                                                             'cumulative_timings'))

    # Time spent in a workunit, not including its children.
    self.self_timings = AggregatedTimings(os.path.join(self.run_info_dir, 'self_timings'))

    # Hit/miss stats for the artifact cache.
    self.artifact_cache_stats = ArtifactCacheStats(os.path.join(self.run_info_dir,
                                                                'artifact_cache_stats'))

    # Daemon stats.
    self.pantsd_stats = PantsDaemonStats()

    self._all_options = all_options

    return (run_id, run_uuid)
73036
def size
      size = {
        width:  @width,
        height: @height
      }

      # Specific size
      unless @options[:width].nil? && @options[:height].nil?
        size[:width]  = @options[:width].nil?  ? calculate_width(@options[:height]) : @options[:width]
        size[:height] = @options[:height].nil? ? calculate_height(@options[:width]) : @options[:height]
      end

      size
    end
149937
def call_failure_app(env, options = {})
      if config.failure_app
        options.merge!(:attempted_path => ::Rack::Request.new(env).fullpath)
        env["PATH_INFO"] = "/#{options[:action]}"
        env["warden.options"] = options

        _run_callbacks(:before_failure, env, options)
        config.failure_app.call(env).to_a
      else
        raise "No Failure App provided"
      end
    end
383267
def call!(env)
      if (request = Request.new(env)).for_asset_file?
        Response.new(env, request.asset_file).to_rack
      else
        @app.call(env)
      end
    end
492326
def call!(env)
      env['rack.logger'] = @logger

      status, headers, body = nil, nil, nil
      benchmark = Benchmark.measure do
        status, headers, body = @app.call(env)
      end
      log_error(env['deas.error'])
      env['deas.time_taken'] = RoundedTime.new(benchmark.real)

      [status, headers, body]
    end
563697
def main():
    
    logging.basicConfig(level=logging.INFO)

    run_metrics = py_interop_run_metrics.run_metrics()
    summary = py_interop_summary.run_summary()

    valid_to_load = py_interop_run.uchar_vector(py_interop_run.MetricCount, 0)
    py_interop_run_metrics.list_summary_metrics_to_load(valid_to_load)

    for run_folder_path in sys.argv[1:]:
        run_folder = os.path.basename(run_folder_path)
        try:
            run_metrics.read(run_folder_path, valid_to_load)
        except Exception, ex:
            logging.warn("Skipping - cannot read RunInfo.xml: %s - %s"%(run_folder, str(ex)))
            continue
        py_interop_summary.summarize_run_metrics(run_metrics, summary)
        error_rate_read_lane_surface = numpy.zeros((summary.size(), summary.lane_count(), summary.surface_count()))
        for read_index in xrange(summary.size()):
            for lane_index in xrange(summary.lane_count()):
                for surface_index in xrange(summary.surface_count()):
                    error_rate_read_lane_surface[read_index, lane_index, surface_index] = \
                        summary.at(read_index).at(lane_index).at(surface_index).error_rate().mean()
        logging.info("Run Folder: "+run_folder)
        for read_index in xrange(summary.size()):
            read_summary = summary.at(read_index)
            logging.info("Read "+str(read_summary.read().number())+" - Top Surface Mean Error: "+str(error_rate_read_lane_surface[read_index, :, 0].mean()))
473328
def run
      # Like RuboCop itself, we'll lazy load so the task
      # doesn't substantially impact Rakefile load time.
      require 'ruumba'

      analyzer = Ruumba::Analyzer.new(@options)
      puts 'Running Ruumba...'

      exit(analyzer.run(@dir))
    end
238438
def run!
      Thinner.configure do |config|
        @options.each_pair do |key, value|
          config.send("#{key}=".to_sym, value)
        end
      end
      Thinner.purge! @urls
    end
1293657
def run!(runtime_config = {})
			@websocket_config.merge! runtime_config

			EM.run do
				if @websocket_config[:tick_interval]
					EM.add_periodic_timer(@websocket_config[:tick_interval]) do
						socket_trigger(:on_tick, @socket_connected)
					end
				end

				EventMachine::WebSocket.run(host: @websocket_config[:socket_host], port: @websocket_config[:socket_port]) do |socket|
					@socket_active = socket
					socket.onopen do |handshake|
						@socket_connected = true
						socket_trigger(:on_socket_open, handshake)
					end

					socket.onmessage do |msg| 
						process_message(msg)
					end

					socket.onclose do 
						socket_trigger(:on_socket_close)
						@socket_connected = false 
					end
				end
			 
				Launchy.open("http://#{@websocket_config[:http_host]}:#{@websocket_config[:http_port]}/")
				WebsocketGui::SinatraWrapper.view_path = @websocket_config[:view]
				WebsocketGui::SinatraWrapper.run!(
					port: @websocket_config[:http_port], 
					bind: @websocket_config[:http_host])
			end
		end
895522
def method_missing(meth, *args, &block)
      if args.size == 1 and meth =~ /^(.+)=$/
        self[$1.to_sym] = args[0]
      else
        super meth, *args, &block
      end
    end
732524
def controller_runtime(name, log_subscriber)
      runtime_attr = "#{name.to_s.underscore}_runtime".to_sym
      Module.new do
        extend ActiveSupport::Concern
        attr_internal runtime_attr

        protected

        define_method :process_action do |action, *args|
          log_subscriber.reset_runtime
          super(action, *args)
        end

        define_method :cleanup_view_runtime do |&block|
          runtime_before_render = log_subscriber.reset_runtime
          send("#{runtime_attr}=",
               (send(runtime_attr) || 0) + runtime_before_render)
          runtime = super(&block)
          runtime_after_render = log_subscriber.reset_runtime
          send("#{runtime_attr}=", send(runtime_attr) + runtime_after_render)
          runtime - runtime_after_render
        end

        define_method :append_info_to_payload do |payload|
          super(payload)
          runtime = (send(runtime_attr) || 0) + log_subscriber.reset_runtime
          payload[runtime_attr] = runtime
        end

        const_set(:ClassMethods, Module.new do
          define_method :log_process_action do |payload|
            messages = super(payload)
            runtime = payload[runtime_attr]
            if runtime && runtime != 0
              messages << format("#{name}: %.1fms", runtime.to_f)
            end
            messages
          end
        end)
      end
    end
943543
def summary
      # Guard against the exceptions array being removed/changed or emptied here
      if exceptions.respond_to?(:first) && exceptions.first
        {
          :error_class => exceptions.first[:errorClass],
          :message => exceptions.first[:message],
          :severity => severity
        }
      else
        {
          :error_class => "Unknown",
          :severity => severity
        }
      end
    end