Class: Pod::Command::Browse

Inherits:
Pod::Command show all
Extended by:
Executable
Defined in:
lib/pod/command/browse.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Browse

Returns a new instance of Browse.



20
21
22
23
24
25
26
# File 'lib/pod/command/browse.rb', line 20

def initialize(argv)
  @spec = argv.flag?('spec')
  @release = argv.flag?('release')
  @info = argv.flag?('info')
  @names = argv.arguments! unless argv.arguments.empty?
  super
end

Class Method Details

.optionsObject



12
13
14
15
16
17
18
# File 'lib/pod/command/browse.rb', line 12

def self.options
  [
    ['--spec', 'Open the podspec in the browser.'],
    ['--release', 'Open the releases in the browser.'],
    ['--info', 'Show more pods information of github (very slowly)'],
  ].concat(super)
end

Instance Method Details

#formated_name(pod) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/pod/command/browse.rb', line 99

def formated_name(pod)
  text = format('%s (%s)', pod.name.green, pod.license)
  text << format("\n\tWatchers: %5s, Forks: %5s, Last Pushed: %s",
                 pod.github_watchers || '-',
                 pod.github_forks || '-',
                 pod.github_last_activity.try(:yellow) || '-',
                 ) if @info
  text << "\n\t#{pod.summary}\n"
end

#interactive_select_sets(sets) ⇒ Object

Raises:

  • (Interrupt)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pod/command/browse.rb', line 76

def interactive_select_sets(sets)
  UI.puts "found #{sets.size} pods"
  UI.title 'Please select a pod:'

  statistics_provider = Config.instance.spec_statistics_provider
  sets.each_with_index do |s, i|
    pod = Specification::Set::Presenter.new(s, statistics_provider)
    UI.puts "  [#{i + 1}]\t#{formated_name(pod)}\n"
  end
  print "> (1-#{sets.size}) "
  input = $stdin.gets
  raise Interrupt unless input

  specs = []
  range = 1..sets.size
  input.split(',').each do |i|
    index = i.try(:strip).to_i
    specs << sets[index - 1].specification.root if range.include?(index)
  end
  raise Informative, 'invalid input value' if specs.empty?
  specs
end

#pick_open_url(spec) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/pod/command/browse.rb', line 109

def pick_open_url(spec)
  url = spec.homepage
  if @spec && url =~ %r{^https?://github.com/}
    format('%s/tree/master/%s.podspec', url, spec.name)
  elsif @release && url =~ %r{^https?://github.com/}
    format('%s/releases', url)
  else
    url
  end
end

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pod/command/browse.rb', line 36

def run
  # update_specs_repos
  @names.each do |name|
    specs = specs_with_name(name)
    next unless specs

    specs.each do |spec|
      UI.message "Opening #{spec.name}" do
        url = pick_open_url(spec)
        open!(url)
      end
    end
  end
end

#specs_with_name(name) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pod/command/browse.rb', line 59

def specs_with_name(name)
  specs = []
  if set = SourcesManager.search(Dependency.new(name))
    specs << set.specification.root
  elsif sets = Pod::SourcesManager.search_by_name(name)
    case sets.size
    when 1
      specs << sets.first.specification.root
    else
      specs = interactive_select_sets(sets)
    end
  else
    raise Informative, "Unable to find a podspec named `#{name}`"
  end
  specs
end

#update_specs_reposObject



51
52
53
54
55
56
57
# File 'lib/pod/command/browse.rb', line 51

def update_specs_repos
  return if config.skip_repo_update?

  UI.section 'Updating spec repositories' do
    SourcesManager.update
  end
end

#validate!Object



28
29
30
31
# File 'lib/pod/command/browse.rb', line 28

def validate!
  super
  help! 'A Pod name is required' unless @names
end