Class: BiblioTech::Tasklib

Inherits:
Mattock::Tasklib
  • Object
show all
Defined in:
lib/bibliotech/rake_lib.rb

Instance Method Summary collapse

Instance Method Details

#default_configurationObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/bibliotech/rake_lib.rb', line 11

def default_configuration
  super
  self.app = App.new

  self.config_path = app.config_path
  from_hash(app.config.hash)
  @default_state = to_hash
  @default_state.delete(:app)
  @default_state.delete(:config_path)
end

#defineObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/bibliotech/rake_lib.rb', line 41

def define
  in_namespace do
    namespace :backups do
      desc "Restore from a named DB backup"
      task :restore, [:name] do |task, args|
        fail ":name is required" if args[:name].nil?
        options = { :backups => { :filename => args[:name] } }
        if %r[/] =~ args[:name]
          options = { :backups => { :file => args[:name] } }
        end
        app.import(options)
      end

      task :create, [:prefix] do |task, args|
        options = {}
        unless args[:prefix].nil?
          options[:backups] = {:prefix => args[:prefix]}
        end
        app.create_backup(options)
      end

      task :clean, [:prefix] do |task, args|
        options = {}
        unless args[:prefix].nil?
          options[:backups] = {:prefix => args[:prefix]}
        end
        app.prune(options)
      end

      desc "Run DB backups, including cleaning up the resulting backups"
      task :perform, [:prefix] => [:create, :clean]
    end

    namespace :remote_sync do
      desc "Pull the latest DB dump from the remote server into our local DB"
      task :down do
        result = app.remote_cli(remote, "latest")
        result.must_succeed!
        filename = result.stdout.chomp

        app.get(remote, filename).must_succeed!
        app.import(:backups => { :file => app.config.local_file(filename)}).must_succeed!
      end

      desc "Push the latest local DB dump to the remote server's DB"
      task :up do
        filename = app.latest
        app.send(remote, filename).must_succeed!
        app.remote_cli(remote, "load", filename).must_succeed!
      end
    end
  end
end

#resolve_configurationObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bibliotech/rake_lib.rb', line 22

def resolve_configuration
  configured_state = to_hash
  configured_state.delete(:app)
  configured_state.delete(:config_path)
  case [config_path == app.config_path, configured_state == to_hash.delete(:config_path)]
  when [false, false]
  when [true, true]
    raise "Cannot both change to config path and any other setting (sorry) - put configs in a file"
  when [true, false]
    app.config.hash.merge!(configured_state)
  when [false, true]
    app.config_path = config_path
    app.reset
  end
  super
end