class SocialSnippet::CommandLine::SSpm::SubCommands::InstallCommand
Public Instance Methods
define_options()
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 26 def define_options define_option :dry_run, :type => :flag, :short => true, :default => false define_option :name, :short => true, :default => nil end
desc()
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 22 def desc "Install snippet repository" end
install_by_names()
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 47 def install_by_names while has_next_token? token_str = next_token repo_info = parse_repo_token(token_str) if is_name?(token_str) url = core.api.resolve_name_by_registry(repo_info[:name]) core.api.install_repository url, repo_info[:ref], options elsif is_url?(token_str) repo_url = repo_info[:name] core.api.install_repository repo_url, repo_info[:ref], options elsif is_path?(token_str) repo_path = repo_info[:name] core.api.install_repository repo_path, repo_info[:ref], options end end end
install_by_snippet_json()
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 39 def install_by_snippet_json snippet_json = ::JSON.parse(File.read("snippet.json")) snippet_json["dependencies"].each do |name, ref| url = core.api.resolve_name_by_registry(name) core.api.install_repository url, ref, options end end
run()
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 31 def run if has_next_token? install_by_names else install_by_snippet_json end end
usage()
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 5 def usage <<EOF Usage: sspm install [options] [--] <repo> [<repo> ...] <repo>'s format: <name> (e.g. "example-repo") <name>#<version> (e.g. "example-repo#0.0.1") Example: $ sspm install example-repo -> Installed latest version (or remote's current ref) $ sspm install example-repo#0.0.1 -> Installed as the specified version EOF end
Private Instance Methods
has_ref?(token_str)
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 93 def has_ref?(token_str) /#/ === token_str end
is_name?(s)
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 66 def is_name?(s) not /\// === s end
is_path?(s)
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 70 def is_path?(s) pathname = ::Pathname.new(s) pathname.absolute? || pathname.relative? end
is_url?(s)
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 75 def is_url?(s) ::URI::regexp === s end
parse_repo_token(token_str)
click to toggle source
# File lib/social_snippet/command_line/sspm/sub_commands/install_command.rb, line 79 def parse_repo_token(token_str) if has_ref?(token_str) words = token_str.split("#", 2) { :name => words.shift, :ref => words.shift, } else { :name => token_str, } end end