Class: Burn::Initializer

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

Overview

An initializer to be placed in the config/initializers directory. This should be used like Rails::Initializer.

Burn::Initializer.run do |config|
  config.crash_server = "http://my.crash.server:1234/"

  # Etc.
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run {|new| ... } ⇒ Object

Yields a new initializer to the block

Yields:

  • (new)


12
13
14
# File 'lib/initializer.rb', line 12

def self.run
  yield new if block_given?
end

Instance Method Details

#build_backup(&block) ⇒ Object

This takes a block which creates the backup. The block should return the raw backup data. If the backup creates a tarball, then this method should return the contents of that tarball.

# A not terribly effective backup
config.build_backup do
  ToplevelModel.find(1).to_xml
end


29
30
31
32
33
34
# File 'lib/initializer.rb', line 29

def build_backup &block
  Burn::BurnController.class_eval do
    remove_method :build_backup
    define_method :build_backup, &block
  end
end

#crash_server=(crash_server) ⇒ Object

Sets the default backup server



17
18
19
# File 'lib/initializer.rb', line 17

def crash_server= crash_server
  Burn::Crash.site = crash_server
end

#load_backup(&block) ⇒ Object

This takes a block which restores from the backup. The block will receive the raw backup data. If the backup created a tarball, then this method will receive the contents of that tarball.

# A not terribly effective restore
config.load_backup do |data|
  ToplevelModel.new.from_xml(data).save
end


44
45
46
47
48
49
# File 'lib/initializer.rb', line 44

def load_backup &block
  Burn::BurnController.class_eval do
    remove_method :load_backup
    define_method :load_backup, &block
  end
end