class CocoapodsRepoSq::RepositoryStore

Class responsible for managing user configured Square SDK repositories. Repository settings and a local copy of the podspecs are stored on the filesystem inside Cocoapods' home directory.

Public Class Methods

default() click to toggle source

Default store located in Cocoapods's home directory. Used by the plugin to look for registered repositories or by the `repo-sq` commands to manage registered repositories.

@return [RepositoryStore]

the default RepositoryStore
# File lib/cocoapods_repo_sq/repository_store.rb, line 35
def self.default
  @default ||= new
end
new(path = nil) click to toggle source

@param path [String]

the path where all Square SDK repositories will be stored. If no path
is provided a default `$COCOAPODS_HOME/repo-sq` will be used
# File lib/cocoapods_repo_sq/repository_store.rb, line 42
def initialize(path = nil)
  path ||= File.join(Pod::Config.instance.home_dir, 'repo-sq')
  @path = ensure_path(path)
end

Public Instance Methods

exists?(name) click to toggle source

Indicates if a Square SDK repository has been added to the store

@param name [String]

the Square SDK repository name to look for

@return [Boolean]

`true` if the targeted Square SDK repository is configured in this
repository store, otherwise `false`.
# File lib/cocoapods_repo_sq/repository_store.rb, line 55
def exists?(name)
  File.exists?(settings_path(name))
end
get(name) click to toggle source

Returns a {Repository} instance if a Square SDK repository exists in the store with the given name

@param name [String]

the Square SDK repository name to look for

@return [Repository]

a Square SDK repository
# File lib/cocoapods_repo_sq/repository_store.rb, line 79
def get(name)
  return unless exists?(name)

  settings = load_settings!(name)
  Repository.new(
    settings[:name],
    settings[:username],
    settings[:password],
    settings[:url],
    repository_path(name)
  )
end
list() click to toggle source

Returns all repositories currently configured in the store as a list of {Repository} objects

@return [Array<Repository>]

the list of all Square SDK repositories
# File lib/cocoapods_repo_sq/repository_store.rb, line 64
def list
  Dir[File.join(@path, '*')].map do |dir|
    name = File.basename(dir)
    get(name)
  end.compact
end
register(name, username, password, url) click to toggle source

Registers a Square SDK repository on the local store

@param name [String]

the Square SDK repository name.

@param username [String]

the Square SDK repository username.

@param password [String]

the Square SDK repository password.

@param url [String]

the Square SDK repositories server URL.

@return [Repository]

a Square SDK repository

@raise [Pod::Informative]

if the repository has already been configured
# File lib/cocoapods_repo_sq/repository_store.rb, line 111
def register(name, username, password, url)
  if exists?(name)
    message = "Square SDK repository `#{name}` is already configured"
    raise Pod::Informative, message
  end

  begin
    store_settings!(name, username, password, url)
    Repository.new(name, username, password, url, repository_path(name))
  rescue => error
    remove(name)
    raise error
  end
end
remove(name) click to toggle source

Removes a Square SDK repository from the local store

@param name [String]

the name of the Square SDK Repository to be removed.

@return [Boolean]

`true` if the targeted Square SDK repository was removed from the store,
otherwise `false`.
# File lib/cocoapods_repo_sq/repository_store.rb, line 134
def remove(name)
  path = repository_path(name)
  File.exists?(path) && FileUtils.rm_rf(path) && true
end

Private Instance Methods

ensure_path(path) click to toggle source
# File lib/cocoapods_repo_sq/repository_store.rb, line 157
def ensure_path(path)
  FileUtils.mkpath(path)
  path
end
load_settings!(name) click to toggle source
# File lib/cocoapods_repo_sq/repository_store.rb, line 140
def load_settings!(name)
  YAML.load_file(settings_path(name))
end
repository_path(name) click to toggle source
# File lib/cocoapods_repo_sq/repository_store.rb, line 162
def repository_path(name)
  File.join(@path, name)
end
settings_path(name) click to toggle source
# File lib/cocoapods_repo_sq/repository_store.rb, line 166
def settings_path(name)
  File.join(repository_path(name), '.settings.yml')
end
store_settings!(name, username, password, url) click to toggle source
# File lib/cocoapods_repo_sq/repository_store.rb, line 144
def store_settings!(name, username, password, url)
  settings = {
    name: name,
    username: username,
    password: password,
    url: url
  }

  settings_filename = settings_path(name)
  ensure_path(File.dirname(settings_filename))
  File.open(settings_filename, 'w') { |f| YAML.dump(settings, f) }
end