Sha256: a97928e05b5f08d3225ed6248af1962ccf859e86729e6dc586adc22b425dc05c

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

module CocoaPodsStats
  class SpecsRepoValidator
    def validates?(source)
      source && source.url.end_with?('CocoaPods/Specs.git')
    end
  end

  class OptOutValidator
    def validates?
      ENV['COCOAPODS_DISABLE_STATS'].nil?
    end
  end

  Pod::HooksManager.register('cocoapods-stats', :post_install) do |context, _|
    require 'set'
    require 'cocoapods'
    require 'cocoapods_stats/target_mapper'
    require 'cocoapods_stats/sender'

    validator = OptOutValidator.new
    break unless validator.validates?

    master_source = Pod::SourcesManager.master.first
    validator = SpecsRepoValidator.new
    break unless validator.validates?(master_source)

    Pod::UI.titled_section 'Sending stats' do
      master_pods = Set.new(master_source.pods)

      mapper = TargetMapper.new
      targets = mapper.pods_from_project(context, master_pods)

      # Logs out for now:
      targets.flat_map { |t| t[:pods] }.uniq.sort_by { |p| p[:name] }.each do |pod|
        Pod::UI.message "#{pod[:name]}, #{pod[:version]}", '- '
      end

      is_pod_try = defined?(Pod::Command::Try::TRY_TMP_DIR) &&
        context.sandbox_root.start_with?(Pod::Command::Try::TRY_TMP_DIR.to_s)

      # Send the analytics stuff up
      Sender.new.send(targets, :pod_try => is_pod_try)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cocoapods-stats-0.5.1 lib/cocoapods_plugin.rb
cocoapods-stats-0.5.0 lib/cocoapods_plugin.rb