Class: BiblioTech::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/bibliotech/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication



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_hashObject

Returns the value of attribute config_hash.



8
9
10
# File 'lib/bibliotech/application.rb', line 8

def config_hash
  @config_hash
end

#config_pathObject

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

#commandsObject



36
37
38
# File 'lib/bibliotech/application.rb', line 36

def commands
  @memos[:command] ||= CommandGenerator.new(config)
end

#configObject



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(options)
  time = Time.now.utc
  pruner = pruner(options)
  return unless pruner.backup_needed?(time)
  options["backups"] ||= options[:backups] || {}
  options["backups"]["filename"] = pruner.filename_for(time)
  export(options)
end

#export(options) ⇒ Object



56
57
58
# File 'lib/bibliotech/application.rb', line 56

def export(options)
  @shell.run(commands.export(options))
end

#get(remote, options) ⇒ Object

pull a dump from a remote



70
71
72
# File 'lib/bibliotech/application.rb', line 70

def get(remote, options)
  @shell.run(commands.fetch(remote, options))
end

#import(options) ⇒ Object



52
53
54
# File 'lib/bibliotech/application.rb', line 52

def import(options)
  @shell.run(commands.import(options))
end

#latest(options = nil) ⇒ Object

return the latest dump of the DB



85
86
87
# File 'lib/bibliotech/application.rb', line 85

def latest(options = nil)
  pruner(options || {}).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(options=nil)
  pruner(options || {}).go
end

#prune_list(options) ⇒ Object



44
45
46
# File 'lib/bibliotech/application.rb', line 44

def prune_list(options)
  pruner(options).list
end

#pruner(options) ⇒ Object



40
41
42
# File 'lib/bibliotech/application.rb', line 40

def pruner(options)
  Backups::Pruner.new(config.merge(options))
end

#remote_cli(remote, command, *options) ⇒ Object



89
90
91
# File 'lib/bibliotech/application.rb', line 89

def remote_cli(remote, command, *options)
  @shell.run(commands.remote_cli(remote, command, *options))
end

#resetObject



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, options)
  @shell.run(commands.push(remote, options))
end

#valiseObject



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