Class: CocoapodsRepoSq::RepositoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods_repo_sq/repository_store.rb

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ RepositoryStore

Returns a new instance of RepositoryStore

Parameters:

  • path (String) (defaults to: nil)

    the path where all Square SDK repositories will be stored. If no path is provided a default $COCOAPODS_HOME/repo-sq will be used



42
43
44
45
# 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

Class Method Details

.defaultRepositoryStore

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.

Returns:



35
36
37
# File 'lib/cocoapods_repo_sq/repository_store.rb', line 35

def self.default
  @default ||= new
end

Instance Method Details

#exists?(name) ⇒ Boolean

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

Parameters:

  • name (String)

    the Square SDK repository name to look for

Returns:

  • (Boolean)

    true if the targeted Square SDK repository is configured in this repository store, otherwise false.



55
56
57
# File 'lib/cocoapods_repo_sq/repository_store.rb', line 55

def exists?(name)
  File.exists?(settings_path(name))
end

#get(name) ⇒ Repository

Returns a CocoapodsRepoSq::Repository instance if a Square SDK repository exists in the store with the given name

Parameters:

  • name (String)

    the Square SDK repository name to look for

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
# 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

#listArray<Repository>

Returns all repositories currently configured in the store as a list of CocoapodsRepoSq::Repository objects

Returns:

  • (Array<Repository>)

    the list of all Square SDK repositories



64
65
66
67
68
69
# 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) ⇒ Repository

Registers a Square SDK repository on the local store

Parameters:

  • name (String)

    the Square SDK repository name.

  • username (String)

    the Square SDK repository username.

  • password (String)

    the Square SDK repository password.

  • url (String)

    the Square SDK repositories server URL.

Returns:

Raises:

  • (Pod::Informative)

    if the repository has already been configured



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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) ⇒ Boolean

Removes a Square SDK repository from the local store

Parameters:

  • name (String)

    the name of the Square SDK Repository to be removed.

Returns:

  • (Boolean)

    true if the targeted Square SDK repository was removed from the store, otherwise false.



134
135
136
137
# 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