Class: RightPublish::Repo
- Inherits:
-
Object
- Object
- RightPublish::Repo
- Defined in:
- lib/right_publish/repo.rb
Constant Summary collapse
- LOCK_FILE_NAME =
'lock.txt'- LOCK_PERIOD =
30 minutes
30 * 60
- LOCK_RETRY_INTERVAL =
1 minute
1 * 60
Instance Method Summary collapse
-
#add(file_or_dir, targe) ⇒ Object
Add a new package to local storage and reindex if necessary.
-
#annotate(options = {}) ⇒ Object
Create an index.html file to enable browsing of this repo’s subdir.
-
#initialize(option_key) ⇒ Repo
constructor
A new instance of Repo.
-
#publish(file_or_dir, target) ⇒ Object
Perform one-shot publish of one or more packages.
-
#pull ⇒ Object
Sync files from remote to local storage.
-
#push ⇒ Object
Sync files from local to remote storage.
Constructor Details
#initialize(option_key) ⇒ Repo
Returns a new instance of Repo.
41 42 43 |
# File 'lib/right_publish/repo.rb', line 41 def initialize(option_key) @repository_type ||= option_key end |
Instance Method Details
#add(file_or_dir, targe) ⇒ Object
Add a new package to local storage and reindex if necessary
107 108 109 |
# File 'lib/right_publish/repo.rb', line 107 def add(file_or_dir, targe) raise NotImplementedError, "Subclass responsibility" end |
#annotate(options = {}) ⇒ Object
Create an index.html file to enable browsing of this repo’s subdir.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/right_publish/repo.rb', line 72 def annotate(={}) Profile.log("Creating HTML directory listing for #{repo_human_name} files...") [:subdir] ||= repo_config[:subdir] files = [] RightPublish::Storage.ls(local_storage, :subdir => [:subdir]) do |file| files << file end # Build merged options hash for annotation, based on profile config plus some options # passed into our class. = Profile.config[:annotation] ? Profile.config[:annotation].dup : {} [:filter] = [:filter] if .key?(:filter) strip = [:subdir].split('/').size html = RightPublish::Annotation.generate_html(files, strip, ) output = File.join(repo_config[:subdir], 'index.html') local_dir = local_storage.get_directories local_dir.files.create(:key => output, :body => html) end |
#publish(file_or_dir, target) ⇒ Object
Perform one-shot publish of one or more packages. “One-shot” means: pull, add, annotate and push.
97 98 99 100 101 102 103 104 |
# File 'lib/right_publish/repo.rb', line 97 def publish(file_or_dir, target) lock do pull add(file_or_dir, target) annotate push end end |
#pull ⇒ Object
Sync files from remote to local storage
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/right_publish/repo.rb', line 46 def pull() Profile.log("Fetching #{repo_human_name} files from remote...") begin sync_dirs(remote_storage, local_storage, repo_config[:subdir]) rescue Exception => e RightPublish::Profile.log("Could not synchronize storage:\n\t#{e}", :error) raise RuntimeError, "pull from remote failed." end end |
#push ⇒ Object
Sync files from local to remote storage
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/right_publish/repo.rb', line 58 def push() Profile.log("Committing local #{repo_human_name} files to remote...") begin sync_dirs(local_storage, remote_storage, repo_config[:subdir]) rescue Exception => e RightPublish::Profile.log("Could not sychronize storage:\n\t#{e}", :error) raise RuntimeError, "push to remote failed." end end |