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.



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

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

Class Method Details

.optionsObject



12
13
14
15
16
17
# 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.'],
  ].concat(super)
end

Instance Method Details

#formated_name(pod) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/pod/command/browse.rb', line 91

def formated_name(pod)
  format('%-40s (Watchers: %5s, Forks: %5s, Pushed: %s)',
         pod.name.green,
         pod.github_watchers || '-',
         pod.github_forks || '-',
         pod.github_last_activity.try(:yellow) || '-',
        )
end

#pick_open_url(spec) ⇒ Object



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

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



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

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

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

#specs_with_name(name) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pod/command/browse.rb', line 57

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

      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?
    end
  else
    raise Informative, "Unable to find a podspec named `#{name}`"
  end
  specs
end

#update_specs_reposObject



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

def update_specs_repos
  return if config.skip_repo_update?

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

#validate!Object



26
27
28
29
# File 'lib/pod/command/browse.rb', line 26

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