Class: BiblioTech::Application
- Inherits:
-
Object
- Object
- BiblioTech::Application
- Defined in:
- lib/bibliotech/application.rb
Instance Attribute Summary collapse
-
#config_hash ⇒ Object
Returns the value of attribute config_hash.
-
#config_path ⇒ Object
Returns the value of attribute config_path.
-
#shell ⇒ Object
writeonly
Sets the attribute shell.
Instance Method Summary collapse
- #commands ⇒ Object
- #config ⇒ Object
- #create_backup(options) ⇒ Object
- #export(options) ⇒ Object
-
#get(remote, options) ⇒ Object
pull a dump from a remote.
- #import(options) ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
-
#latest(options = nil) ⇒ Object
return the latest dump of the DB.
-
#prune(options = nil) ⇒ Object
clean up the DB dumps.
- #prune_list(options) ⇒ Object
- #pruner(options) ⇒ Object
- #remote_cli(remote, command, *options) ⇒ Object
- #reset ⇒ Object
-
#send(remote, options) ⇒ Object
push a dump to a remote.
- #valise ⇒ Object
Constructor Details
#initialize ⇒ Application
11 12 13 14 15 |
# File 'lib/bibliotech/application.rb', line 11 def initialize @memos = {} @shell = Caliph.new @config_path = %w{/etc/bibliotech /usr/share/bibliotech ~/.bibliotech ./.bibliotech ./config/bibliotech} end |
Instance Attribute Details
#config_hash ⇒ Object
Returns the value of attribute config_hash.
8 9 10 |
# File 'lib/bibliotech/application.rb', line 8 def config_hash @config_hash end |
#config_path ⇒ Object
Returns the value of attribute config_path.
8 9 10 |
# File 'lib/bibliotech/application.rb', line 8 def config_path @config_path end |
#shell=(value) ⇒ Object (writeonly)
Sets the attribute shell
9 10 11 |
# File 'lib/bibliotech/application.rb', line 9 def shell=(value) @shell = value end |
Instance Method Details
#commands ⇒ Object
36 37 38 |
# File 'lib/bibliotech/application.rb', line 36 def commands @memos[:command] ||= CommandGenerator.new(config) end |
#config ⇒ Object
32 33 34 |
# File 'lib/bibliotech/application.rb', line 32 def config @memos[:config] ||= Config.new(valise) end |
#create_backup(options) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/bibliotech/application.rb', line 60 def create_backup() time = Time.now.utc pruner = pruner() return unless pruner.backup_needed?(time) ["backups"] ||= [:backups] || {} ["backups"]["filename"] = pruner.filename_for(time) export() end |
#export(options) ⇒ Object
56 57 58 |
# File 'lib/bibliotech/application.rb', line 56 def export() @shell.run(commands.export()) end |
#get(remote, options) ⇒ Object
pull a dump from a remote
70 71 72 |
# File 'lib/bibliotech/application.rb', line 70 def get(remote, ) @shell.run(commands.fetch(remote, )) end |
#import(options) ⇒ Object
52 53 54 |
# File 'lib/bibliotech/application.rb', line 52 def import() @shell.run(commands.import()) end |
#latest(options = nil) ⇒ Object
return the latest dump of the DB
85 86 87 |
# File 'lib/bibliotech/application.rb', line 85 def latest( = nil) pruner( || {}).most_recent.path end |
#prune(options = nil) ⇒ Object
clean up the DB dumps
80 81 82 |
# File 'lib/bibliotech/application.rb', line 80 def prune(=nil) pruner( || {}).go end |
#prune_list(options) ⇒ Object
44 45 46 |
# File 'lib/bibliotech/application.rb', line 44 def prune_list() pruner().list end |
#pruner(options) ⇒ Object
40 41 42 |
# File 'lib/bibliotech/application.rb', line 40 def pruner() Backups::Pruner.new(config.merge()) end |
#remote_cli(remote, command, *options) ⇒ Object
89 90 91 |
# File 'lib/bibliotech/application.rb', line 89 def remote_cli(remote, command, *) @shell.run(commands.remote_cli(remote, command, *)) end |
#reset ⇒ Object
48 49 50 |
# File 'lib/bibliotech/application.rb', line 48 def reset @memos.clear end |
#send(remote, options) ⇒ Object
push a dump to a remote
75 76 77 |
# File 'lib/bibliotech/application.rb', line 75 def send(remote, ) @shell.run(commands.push(remote, )) end |
#valise ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bibliotech/application.rb', line 17 def valise @memos[:valise] ||= begin dirs = config_path Valise::define do dirs.reverse.each do |dir| rw dir end ro from_here(%w{.. default_configuration}, up_to("lib")) handle "*.yaml", :yaml, :hash_merge handle "*.yml", :yaml, :hash_merge end end end |