Class: Pod::Command::PodfileInfo

Inherits:
Pod::Command show all
Defined in:
lib/pod/command/podfile_info.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ PodfileInfo

Returns a new instance of PodfileInfo.



23
24
25
26
27
28
29
30
31
32
# File 'lib/pod/command/podfile_info.rb', line 23

def initialize(argv)
  @info_all = argv.flag?('all')
  
  @type = :text
  @type = :md if argv.flag?('md')
  @type = :csv if argv.flag?('csv')

  @podfile_path = argv.shift_argument
  super
end

Class Method Details

.optionsObject



15
16
17
18
19
20
21
# File 'lib/pod/command/podfile_info.rb', line 15

def self.options
  [
      ["--all", "Show information about all Pods with dependencies that are used in a project"],
      ["--md", "Output information in Markdown format"],
      ["--csv", "Output information in CSV format"]
  ].concat(super)
end

Instance Method Details

#pods_from_podfile(podfile) ⇒ Object



59
60
61
62
63
64
# File 'lib/pod/command/podfile_info.rb', line 59

def pods_from_podfile(podfile)
  pods = []
  podfile.root_target_definitions.each {|e| h = e.to_hash; pods << h['dependencies'] if h['dependencies']}
  pods.flatten!
  pods.collect! {|pod| (pod.is_a?(Hash)) ? pod.keys.first : pod}
end

#pods_info(pods, type) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/pod/command/podfile_info.rb', line 79

def pods_info(pods, type)
  pods = pods_info_hash(pods, [:name, :version, :homepage, :summary, :license])
  UI.puts "name,version,homepage,summary,license" if type == :csv

  pods.each do |pod|
    case type
    when :md
      UI.puts "* [#{pod[:name]} - #{pod[:version]}](#{pod[:homepage]}) [#{pod[:license][:type]}] - #{pod[:summary]}"
    when :csv
      UI.puts "#{pod[:name]},#{pod[:version]},#{pod[:homepage]},\"#{pod[:summary]}\",\"#{pod[:license][:type]}\""
    else
      UI.puts "- #{pod[:name]} (#{pod[:version]}) [#{pod[:license][:type]}]".green
      UI.puts "  #{pod[:summary]}\n\n"
    end
  end
end

#pods_info_hash(pods, keys = [:name, :version, :homepage, :summary, :license]) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/pod/command/podfile_info.rb', line 66

def pods_info_hash(pods, keys=[:name, :version, :homepage, :summary, :license])
  pods_info = []
  pods.each do |pod|
    spec = (Pod::SourcesManager.search_by_name(pod).first rescue nil)
    if spec
      info = {}
      keys.each { |k| info[k] = spec.specification.send(k) }
      pods_info << info
    end
  end
  pods_info
end

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pod/command/podfile_info.rb', line 34

def run
  use_podfile = (@podfile_path || !config.lockfile)

  if !use_podfile
    UI.puts "Using lockfile" if config.verbose?
    verify_lockfile_exists!
    lockfile = config.lockfile
    pods = lockfile.pod_names
    if @info_all
      deps = lockfile.dependencies.map{|d| d.name}
      pods = (deps + pods).uniq
    end
  elsif @podfile_path
    podfile = Pod::Podfile.from_file(@podfile_path)
    pods = pods_from_podfile(podfile)
  else
    verify_podfile_exists!
    podfile = config.podfile
    pods = pods_from_podfile(podfile)
  end

  UI.puts "\nPods used:\n".yellow unless @info_in_md
  pods_info(pods, @type)
end