Class: Fastlane::PluginFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugins/plugin_fetcher.rb

Overview

Use the RubyGems API to get all fastlane plugins

Class Method Summary collapse

Class Method Details

.fetch_gems(search_query: nil) ⇒ Object

Returns an array of FastlanePlugin objects



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fastlane/plugins/plugin_fetcher.rb', line 8

def self.fetch_gems(search_query: nil)
  require 'json'
  require 'open-uri'

  page = 1
  plugins = []
  loop do
    url = "https://rubygems.org/api/v1/search.json?query=#{PluginManager.plugin_prefix}#{search_query}&page=#{page}"
    FastlaneCore::UI.verbose("RubyGems API Request: #{url}")
    results = JSON.parse(open(url).read)
    break if results.count == 0

    plugins += results.collect do |current|
      FastlanePlugin.new(current)
    end
    page += 1
  end

  return plugins if search_query.to_s.length == 0
  plugins.keep_if do |current|
    current.full_name.include?(search_query)
  end

  return plugins
end

.update_md_file!(output_path: "docs/AvailablePlugins.md") ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/fastlane/plugins/plugin_fetcher.rb', line 34

def self.update_md_file!(output_path: "docs/AvailablePlugins.md")
  @plugins = fetch_gems

  template_path = File.join(Fastlane::ROOT, "lib/assets/AvailablePlugins.md.erb")
  md = ERB.new(File.read(template_path), nil, '<>').result(binding) # http://www.rrn.dk/rubys-erb-templating-system

  puts md
  File.write(output_path, md)
  FastlaneCore::UI.success("Successfully written plugin file to '#{output_path}'")
end