class Pod::Installer

Public Class Methods

alias_step_method(method_sym) click to toggle source
# File lib/cocoapods-time-analyze/install-hook/install_hook.rb, line 21
def self.alias_step_method(method_sym)
  if method_defined?(method_sym) || private_method_defined?(method_sym)
    alias_method "origin_#{method_sym}".to_sym, method_sym
  else
    raise "Pod::Installer does not have method named #{method_sym}, please check your .cocoapods_time_analyze_config.rb config file"
  end
end

Public Instance Methods

install!() click to toggle source
# File lib/cocoapods-time-analyze/install-hook/install_hook.rb, line 9
def install!
  @time_log = {}

  TimeAnalyzeConfig::PodInstall.target_steps.each { |step| redefine_step_method(step.to_sym) }
  install_start_time = Time.now
  origin_install!
  total_time = (Time.now - install_start_time).round(2)

  TimeAnalyzeConfig::PodInstall.after_all(total_time, @time_log, self)
  write_summary_file(total_time) if TimeAnalyzeConfig::PodInstall.enable_local_summary
end
Also aliased as: origin_install!
origin_install!()
Alias for: install!

Private Instance Methods

redefine_step_method(method_sym) click to toggle source
# File lib/cocoapods-time-analyze/install-hook/install_hook.rb, line 31
def redefine_step_method(method_sym)
  @time_log ||= {}

  block = proc do |*arguments|
    start_time = Time.now
    send("origin_#{method_sym}".to_sym, *arguments)
    total_time = (Time.now - start_time).round(2)
    @time_log[method_sym] = total_time
  end

  self.class.alias_step_method(method_sym)
  self.class.send(:define_method, method_sym, &block)
end
write_summary_file(total_time) click to toggle source
# File lib/cocoapods-time-analyze/install-hook/install_hook.rb, line 45
def write_summary_file(total_time)
  file_name = PodTimeAnalyze::POD_INSTALL_SUMMARY_FILE_NAME
  today = Date.today.to_s
  summary_total_time = total_time.to_i
  summary = File.exist?(file_name) ? YAML.safe_load(File.read(file_name)) : {}
  summary['total_time'] = summary['total_time'] ? summary['total_time'] + summary_total_time : summary_total_time
  summary['detail'] ||= {}
  summary['detail'][today] = summary['detail'][today] ? summary['detail'][today] + summary_total_time : summary_total_time
  File.open file_name, 'w+' do |file|
    file.write(YAML.dump(summary))
  end
end