Class: BiblioTech::CommandGenerator

Inherits:
Object
  • Object
show all
Includes:
Caliph::CommandLineDSL
Defined in:
lib/bibliotech/command_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CommandGenerator

Returns a new instance of CommandGenerator.



14
15
16
# File 'lib/bibliotech/command_generator.rb', line 14

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#createObject

Raises:

  • (NotImplementedError)


82
83
84
# File 'lib/bibliotech/command_generator.rb', line 82

def create()
  raise NotImplementedError
end

#deleteObject

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/bibliotech/command_generator.rb', line 79

def delete()
  raise NotImplementedError
end

#export(options = nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/bibliotech/command_generator.rb', line 18

def export(options = nil)
  options = config.merge(options || {})
  command = cmd
  command = Builders::Export.for(options).go(command)
  Builders::FileOutput.for(options).go(command)
end

#fetch(remote, filename, options = nil) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/bibliotech/command_generator.rb', line 32

def fetch(remote, filename, options = nil)
  options = config.merge(options || {})
  cmd("scp") do |cmd|
    options.optionally{ cmd.options << "-i #{options.id_file(remote)}" }
    cmd.options << options.remote_file(remote, filename)
    cmd.options << options.local_file(filename)
  end
end

#import(options = nil) ⇒ Object



25
26
27
28
29
30
# File 'lib/bibliotech/command_generator.rb', line 25

def import(options = nil)
  options = config.merge(options || {})
  command = cmd()
  command = Builders::Import.for(options).go(command)
  Builders::FileInput.for(options).go(command)
end

#push(remote, filename, options = nil) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/bibliotech/command_generator.rb', line 41

def push(remote, filename, options = nil)
  options = config.merge(options || {})
  cmd("scp") do |cmd|
    cmd.options << options.local_file(filename)
    cmd.options << options.remote_file(remote, filename)
  end
end

#remote_cli(remote, *command_options) ⇒ Object



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
# File 'lib/bibliotech/command_generator.rb', line 49

def remote_cli(remote, *command_options)
  options = {}
  if command_options.last.is_a? Hash
    options = command_options.pop
  end
  options = config.merge(options)
  command_on_remote = cmd("cd") do |cmd|
    cmd.options << options.root_dir_on(remote)
  end & cmd("bundle", "exec", "bibliotech", *command_options)
  cmd("ssh") do |cmd|
    cmd.options << "-n" #because we're not going to be doing any input
    options.optionally{ cmd.options << "-i #{options.id_file(remote)}" }
    options.optionally{ cmd.options << "-l #{options.remote_user(remote)}" }

    cmd.options << options.remote_host(remote)

    options.optionally{ cmd.options << "-p #{options.remote_port(remote)}" } #ok


    options.optionally do
      options.ssh_options(remote).each do |opt|
        cmd.options << "-o #{opt}"
      end
    end
  end - escaped_command(command_on_remote)
end

#wipeObject

Raises:

  • (NotImplementedError)


76
77
78
# File 'lib/bibliotech/command_generator.rb', line 76

def wipe()
  raise NotImplementedError
end