Class: Leda::Runner

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

Overview

Actually runs a dump or restore using the store info in a {Configuration}.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_env, configuration) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
# File 'lib/leda/runner.rb', line 9

def initialize(current_env, configuration)
  @current_env = current_env
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



7
8
9
# File 'lib/leda/runner.rb', line 7

def configuration
  @configuration
end

#current_envObject (readonly)

Returns the value of attribute current_env.



7
8
9
# File 'lib/leda/runner.rb', line 7

def current_env
  @current_env
end

Instance Method Details

#directory(env, data_unit = nil, store = nil) ⇒ Object



14
15
16
17
18
19
# File 'lib/leda/runner.rb', line 14

def directory(env, data_unit=nil, store=nil)
  p = configuration.base_dir.join(env)
  p = p.join(data_unit.name) if data_unit
  p = p.join(store.name) if store
  p
end

#dump(data_unit_name = nil, store_name = nil) ⇒ Object

Performs dumps for the configured stores. Can optionally be limited to one data unit and/or store type.



29
30
31
32
33
34
35
# File 'lib/leda/runner.rb', line 29

def dump(data_unit_name=nil, store_name=nil)
  each_data_unit_store(data_unit_name, store_name).each do |data_unit, store|
    dir = directory(@current_env, data_unit, store)
    dir.mkpath
    store.dump(dir)
  end
end

#dump_relative_paths(data_unit_name = nil, store_name = nil) ⇒ Object



37
38
39
40
41
# File 'lib/leda/runner.rb', line 37

def dump_relative_paths(data_unit_name=nil, store_name=nil)
  each_data_unit_store(data_unit_name, store_name).flat_map do |data_unit, store|
    relative_directory(@current_env, data_unit, store)
  end
end

#relative_directory(env, data_unit = nil, store = nil) ⇒ Object



21
22
23
24
# File 'lib/leda/runner.rb', line 21

def relative_directory(env, data_unit=nil, store=nil)
  directory(@current_env, data_unit, store).
    relative_path_from(configuration.project_root_dir)
end

#restore_from(source_env, data_unit_name = nil, store_name = nil) ⇒ Object

Performs restores for the configured stores. Can optionally be limited to one data unit and/or store type.



46
47
48
49
50
# File 'lib/leda/runner.rb', line 46

def restore_from(source_env, data_unit_name=nil, store_name=nil)
  each_data_unit_store(data_unit_name, store_name).each do |data_unit, store|
    store.restore_from(directory(source_env, data_unit, store))
  end
end