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

#pick_open_url(spec) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/pod/command/browse.rb', line 86

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

#runObject



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

def run
#         update_specs_repos
  @names.each do |name|
    if spec = spec_with_name(name)
      UI.title "Opening #{spec.name}" do
        url = pick_open_url(spec)
        UI.puts(">>> #{url}")
        open!(url)
      end
    end
  end
end

#spec_with_name(name) ⇒ Object



55
56
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
# File 'lib/pod/command/browse.rb', line 55

def spec_with_name(name)
  if set = SourcesManager.search(Dependency.new(name))
    set.specification.root
  elsif sets = Pod::SourcesManager.search_by_name(name)
    set = begin
      case sets.size
      when 1
        sets.first
      when 2..9
        UI.title 'Please select pod:'
        text = ''
        sets.each_with_index do |s, i|
          text << "  [#{i + 1}] #{s.name}\n"
        end
        UI.puts text
        print "> (1-#{sets.size}) "
        input = $stdin.gets
        raise Informative, 'Cancelled' unless input
        index = input.chop.to_i
        raise Informative, 'invalid input value' unless (1..sets.size).include?(index)
        sets[index - 1]
      else
        raise Informative, "Unable to many find a podspec named `#{name}` (#{sets.size})"
      end
    end
    set.specification.root
  else
    raise Informative, "Unable to find a podspec named `#{name}`"
  end
end

#update_specs_reposObject



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

def update_specs_repos
  unless config.skip_repo_update?
    UI.section 'Updating spec repositories' do
      SourcesManager.update
    end
  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