module SocialSnippet::Api::SearchApi

Public Instance Methods

search_repositories(query, options = {}) click to toggle source

$ sspm search query

# File lib/social_snippet/api/search_api.rb, line 4
def search_repositories(query, options = {})
  format_text = search_result_format(options)
  core.registry_client.repositories.search(query).each do |repo|
    output format_text % search_result_list(repo, options)
  end
end

Private Instance Methods

search_result_format(options) click to toggle source
# File lib/social_snippet/api/search_api.rb, line 30
def search_result_format(options)
  keys = [ # TODO: improve (change order by option, etc...)
    :name,
    :desc,
    :url,
    :installed,
  ]

  list = []
  keys.each {|key| list.push "%s" if options[key] }

  return list.join(" ")
end
search_result_installed(repo) click to toggle source
# File lib/social_snippet/api/search_api.rb, line 22
def search_result_installed(repo)
  if core.repo_manager.exists?(repo["name"])
    "#installed"
  else
    ""
  end
end
search_result_list(repo, options) click to toggle source
# File lib/social_snippet/api/search_api.rb, line 13
def search_result_list(repo, options)
  list = []
  list.push repo["name"] if options[:name]
  list.push "\"#{repo["desc"]}\"" if options[:desc]
  list.push repo["url"] if options[:url]
  list.push search_result_installed(repo) if options[:installed]
  return list
end