Class: VhostGenerator::CmdlineBuilder

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

Overview

Represents a Shell command line (to display in vhost comments)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, cwd, progname, env) ⇒ CmdlineBuilder

Returns a new instance of CmdlineBuilder.



9
10
11
12
13
14
# File 'lib/vhost_generator/cmdline_builder.rb', line 9

def initialize(config, cwd, progname, env)
  self.config = config
  self.cwd = cwd
  self.progname = progname
  self.env = env
end

Instance Attribute Details

#config=(value) ⇒ Object (writeonly)

Sets the attribute config

Parameters:

  • value

    the value to set the attribute config to.



7
8
9
# File 'lib/vhost_generator/cmdline_builder.rb', line 7

def config=(value)
  @config = value
end

#cwdObject



16
17
18
# File 'lib/vhost_generator/cmdline_builder.rb', line 16

def cwd
  @cwd ? ['cd', @cwd] : nil
end

#env=(value) ⇒ Object (writeonly)

Sets the attribute env

Parameters:

  • value

    the value to set the attribute env to.



7
8
9
# File 'lib/vhost_generator/cmdline_builder.rb', line 7

def env=(value)
  @env = value
end

#prognameObject



20
21
22
23
24
25
26
27
28
# File 'lib/vhost_generator/cmdline_builder.rb', line 20

def progname
  if @progname
    if @env.keys.grep(/^BUNDLE_/).empty?
      [@progname]
    else
      ['bundle', 'exec', File.basename(@progname)]
    end
  end
end

Instance Method Details

#commandsObject



43
44
45
46
47
48
49
# File 'lib/vhost_generator/cmdline_builder.rb', line 43

def commands
  if prog_name = progname
    [cwd, prog_name + progargs].compact
  else
    []
  end
end

#progargsObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vhost_generator/cmdline_builder.rb', line 30

def progargs
  args = []
  args << '-f' << @config.static_folder
  args << '-l' << @config.server_ports.join(',')
  args << '-s' << @config.server_names.join(',')
  args << '-p' << @config.instance_ports.join(',')
  args << '-r' << @config.relative_root
  args << '-g' << @config.generator
  options = @config.generator_options.collect {|k,v| "#{k}=#{v}" }
  args << '-o' << options.join(',')
  args
end

#to_strObject



51
52
53
54
55
56
57
58
# File 'lib/vhost_generator/cmdline_builder.rb', line 51

def to_str
  parts = commands.collect { |cmd| Shellwords.shelljoin(cmd) }
  if parts.length > 1
    "(#{ parts.join(' && ') })"
  else
    parts.first
  end
end