Class: Pod::Command::GiteeRepo::Publish
- Inherits:
-
Pod::Command::GiteeRepo
- Object
- Pod::Command
- Pod::Command::GiteeRepo
- Pod::Command::GiteeRepo::Publish
- Extended by:
- Executable
- Defined in:
- lib/pod/command/gitee_repo/publish.rb
Constant Summary collapse
- UTIL =
Pod::GiteeRepo::GiteeRepoUtil
Instance Method Summary collapse
-
#initialize(argv) ⇒ Publish
constructor
A new instance of Publish.
- #is_absolute_path(path) ⇒ Object
-
#publish_package_to_repo ⇒ Object
Publish a package to Gitee Repo.
-
#repo_root_dir ⇒ Pathname
The root directory of the repository.
- #run ⇒ Object
- #upload_file(url) ⇒ Object
- #validate! ⇒ Object
Methods inherited from Pod::Command::GiteeRepo
Constructor Details
#initialize(argv) ⇒ Publish
Returns a new instance of Publish.
26 27 28 29 30 31 |
# File 'lib/pod/command/gitee_repo/publish.rb', line 26 def initialize(argv) @repo = argv.shift_argument @target_file_path = argv.shift_argument @path_to_file = argv.shift_argument super end |
Instance Method Details
#is_absolute_path(path) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/pod/command/gitee_repo/publish.rb', line 80 def is_absolute_path(path) # 判断路径是否以'/'或'\\'开头,如果是,则是绝对路径 return true if path.start_with?('/') || path.start_with?('\\') # 如果以上条件都不满足,则不是绝对路径 false end |
#publish_package_to_repo ⇒ Object
Publish a package to Gitee Repo
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pod/command/gitee_repo/publish.rb', line 46 def publish_package_to_repo UI.puts "Publish a package to repo `#{@repo}'\n" url = UTIL.get_gitee_repo_url(repo_root_dir).gsub("api/pods", "repository") begin upload_file(url) rescue => e raise Informative, "Error pushing package to Gitee Repo: #{e.message}" end UI.puts "Package pushed successfully to Gitee Repo".green end |
#repo_root_dir ⇒ Pathname
Returns The root directory of the repository.
74 75 76 77 78 |
# File 'lib/pod/command/gitee_repo/publish.rb', line 74 def repo_root_dir root_dir = config.repos_dir + @repo raise Informative, "'#{@repo}' is not an Gitee-backed Specs repo" unless UTIL.gitee_repo?(root_dir) root_dir end |
#run ⇒ Object
41 42 43 |
# File 'lib/pod/command/gitee_repo/publish.rb', line 41 def run publish_package_to_repo end |
#upload_file(url) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pod/command/gitee_repo/publish.rb', line 57 def upload_file(url) = File.(@path_to_file) parameters = ["-XPUT", "-f", "-L", "#{url}#{@target_file_path}", '-T', "#{file_expand_path}", "--netrc-optional", '--retry', '2'] netrc_path = ENV["COCOAPODS_GITEE_REPO_NETRC_PATH"] parameters.concat(["--netrc-file", Pathname.new(netrc_path).]) if netrc_path art_credentials = ENV["COCOAPODS_GITEE_REPO_CREDENTIALS"] parameters.concat(["--user", art_credentials]) if art_credentials win_ssl_no_revoke = ENV["COCOAPODS_GITEE_REPO_SSL_NO_REVOKE"] parameters.concat(["--ssl-no-revoke"]) if defined? win_ssl_no_revoke && "true".casecmp(win_ssl_no_revoke) curl! parameters end |
#validate! ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/pod/command/gitee_repo/publish.rb', line 33 def validate! super unless @repo && @target_file_path && @path_to_file help! 'This command requires both a repo name and a target_file_path and a path_to_file.' end help! 'Please fill in the absolute path of the file according to the repo root directory' if !is_absolute_path(@target_file_path) end |