Sha256: df6a6b7394b118086f33b87073218ba7cef7dba703a7d94cca06549a442c4d4c

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

module CocoaPodsStats
  class SpecsRepoValidator
    def validates?(source)
      source && source.url && 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
    next unless validator.validates?

    master_source = Pod::SourcesManager.master.first
    validator = SpecsRepoValidator.new
    next 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) &&
        Pod::Command::Try::TRY_TMP_DIR.exist? &&
        context.sandbox_root.start_with?(Pod::Command::Try::TRY_TMP_DIR.realpath.to_s)

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cocoapods-stats-1.0.0.beta.3 lib/cocoapods_plugin.rb
cocoapods-stats-1.0.0.beta.2 lib/cocoapods_plugin.rb
cocoapods-stats-1.0.0.beta.1 lib/cocoapods_plugin.rb
cocoapods-stats-0.6.2 lib/cocoapods_plugin.rb