Class: Fastlane::PluginInfoCollector
- Inherits:
-
Object
- Object
- Fastlane::PluginInfoCollector
- Defined in:
- fastlane/lib/fastlane/plugins/plugin_info_collector.rb
Instance Method Summary collapse
- #author_valid?(author) ⇒ Boolean
- #collect_author(initial_author = nil) ⇒ Object
-
#collect_details ⇒ Object
Summary.
- #collect_email(initial_email = nil) ⇒ Object
- #collect_info(initial_name = nil) ⇒ Object
-
#collect_plugin_name(initial_name = nil) ⇒ Object
Plugin name.
-
#collect_summary ⇒ Object
Summary.
-
#detect_author ⇒ Object
Author.
-
#detect_email ⇒ Object
Email.
-
#fix_plugin_name(name) ⇒ Object
Applies a series of replacement rules to turn the requested plugin name into one that is acceptable, returning that suggestion.
-
#gem_name_taken?(name) ⇒ Boolean
Checks if the gem name is still free on RubyGems.
-
#initialize(ui = PluginGeneratorUI.new) ⇒ PluginInfoCollector
constructor
A new instance of PluginInfoCollector.
- #plugin_name_valid?(name) ⇒ Boolean
- #summary_valid?(summary) ⇒ Boolean
Constructor Details
#initialize(ui = PluginGeneratorUI.new) ⇒ PluginInfoCollector
Returns a new instance of PluginInfoCollector.
3 4 5 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 3 def initialize(ui = PluginGeneratorUI.new) @ui = ui end |
Instance Method Details
#author_valid?(author) ⇒ Boolean
115 116 117 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 115 def () !.to_s.strip.empty? end |
#collect_author(initial_author = nil) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 102 def ( = nil) return if () = nil loop do = @ui.input("What is the plugin author's name?") break if () @ui.('An author name is required.') end end |
#collect_details ⇒ Object
Summary
155 156 157 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 155 def collect_details return @ui.input("Please enter a detailed description of this fastlane plugin:").to_s end |
#collect_email(initial_email = nil) ⇒ Object
128 129 130 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 128 def collect_email(initial_email = nil) return initial_email || @ui.input("What is the plugin author's email address?") end |
#collect_info(initial_name = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 7 def collect_info(initial_name = nil) plugin_name = collect_plugin_name(initial_name) = () email = collect_email(detect_email) summary = collect_summary details = collect_details PluginInfo.new(plugin_name, , email, summary, details) end |
#collect_plugin_name(initial_name = nil) ⇒ Object
Plugin name
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 21 def collect_plugin_name(initial_name = nil) plugin_name = initial_name first_try = true loop do if !first_try || plugin_name.to_s.empty? plugin_name = @ui.input("What would you like to be the name of your plugin?") end first_try = false unless plugin_name_valid?(plugin_name) fixed_name = fix_plugin_name(plugin_name) if plugin_name_valid?(fixed_name) plugin_name = fixed_name if @ui.confirm("\nWould '#{fixed_name}' be okay to use for your plugin name?") end end break if plugin_name_valid?(plugin_name) gem_name = PluginManager.to_gem_name(plugin_name) if gem_name_taken?(gem_name) # Gem name is already taken on RubyGems @ui.("\nThe gem name '#{gem_name}' is already taken on RubyGems, please choose a different plugin name.") else # That's a naming error @ui.("\nPlugin names can only contain lower case letters, numbers, and underscores") @ui.("and should not contain 'fastlane' or 'plugin'.") end end plugin_name end |
#collect_summary ⇒ Object
Summary
136 137 138 139 140 141 142 143 144 145 146 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 136 def collect_summary summary = nil loop do summary = @ui.input("Please enter a short summary of this fastlane plugin:") break if summary_valid?(summary) @ui.('A summary is required.') end summary end |
#detect_author ⇒ Object
Author
97 98 99 100 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 97 def git_name = Helper.backticks('git config --get user.name', print: FastlaneCore::Globals.verbose?).strip return git_name.empty? ? nil : git_name end |
#detect_email ⇒ Object
123 124 125 126 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 123 def detect_email git_email = Helper.backticks('git config --get user.email', print: FastlaneCore::Globals.verbose?).strip return git_email.empty? ? nil : git_email end |
#fix_plugin_name(name) ⇒ Object
Applies a series of replacement rules to turn the requested plugin name into one that is acceptable, returning that suggestion
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 79 def fix_plugin_name(name) name = name.to_s.downcase fixes = { /[\- ]/ => '_', # dashes and spaces become underscores /[^a-z0-9_]/ => '', # anything other than lower case letters, numbers and underscores is removed /fastlane[_]?/ => '', # 'fastlane' or 'fastlane_' is removed /plugin[_]?/ => '' # 'plugin' or 'plugin_' is removed } fixes.each do |regex, replacement| name = name.gsub(regex, replacement) end name end |
#gem_name_taken?(name) ⇒ Boolean
Checks if the gem name is still free on RubyGems
67 68 69 70 71 72 73 74 75 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 67 def gem_name_taken?(name) require 'open-uri' require 'json' url = "https://rubygems.org/api/v1/gems/#{name}.json" response = JSON.parse(open(url).read) return !!response['version'] rescue false end |
#plugin_name_valid?(name) ⇒ Boolean
56 57 58 59 60 61 62 63 64 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 56 def plugin_name_valid?(name) # Only lower case letters, numbers and underscores allowed /^[a-z0-9_]+$/ =~ name && # Does not contain the words 'fastlane' or 'plugin' since those will become # part of the gem name [/fastlane/, /plugin/].none? { |regex| regex =~ name } && # Gem name isn't taken on RubyGems yet !gem_name_taken?(PluginManager.to_gem_name(name)) end |
#summary_valid?(summary) ⇒ Boolean
148 149 150 |
# File 'fastlane/lib/fastlane/plugins/plugin_info_collector.rb', line 148 def summary_valid?(summary) !summary.to_s.strip.empty? end |