Class: VhostGenerator::CmdlineBuilder
- Inherits:
-
Object
- Object
- VhostGenerator::CmdlineBuilder
- Defined in:
- lib/vhost_generator/cmdline_builder.rb
Overview
Represents a Shell command line (to display in vhost comments)
Instance Attribute Summary collapse
-
#config ⇒ Object
writeonly
Sets the attribute config.
- #cwd ⇒ Object
-
#env ⇒ Object
writeonly
Sets the attribute env.
- #progname ⇒ Object
Instance Method Summary collapse
- #commands ⇒ Object
-
#initialize(config, cwd, progname, env) ⇒ CmdlineBuilder
constructor
A new instance of CmdlineBuilder.
- #progargs ⇒ Object
- #to_str ⇒ Object
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
7 8 9 |
# File 'lib/vhost_generator/cmdline_builder.rb', line 7 def config=(value) @config = value end |
#cwd ⇒ Object
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
7 8 9 |
# File 'lib/vhost_generator/cmdline_builder.rb', line 7 def env=(value) @env = value end |
#progname ⇒ Object
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
#commands ⇒ Object
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 |
#progargs ⇒ Object
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 = @config..collect {|k,v| "#{k}=#{v}" } args << '-o' << .join(',') args end |
#to_str ⇒ Object
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 |