Class: MiddlemanWebpacked::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-webpacked/command_runner.rb

Direct Known Subclasses

Build, Server

Constant Summary collapse

AVAILABLE_MODE =
%i[production development none]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ CommandRunner

Returns a new instance of CommandRunner.



24
25
26
27
28
29
30
# File 'lib/middleman-webpacked/command_runner.rb', line 24

def initialize(app, options)
  @app = app
  @options = options
  @arguments = []

  setup
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



22
23
24
# File 'lib/middleman-webpacked/command_runner.rb', line 22

def app
  @app
end

#modeObject (readonly)

Returns the value of attribute mode.



22
23
24
# File 'lib/middleman-webpacked/command_runner.rb', line 22

def mode
  @mode
end

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/middleman-webpacked/command_runner.rb', line 22

def options
  @options
end

Class Method Details

.bin(path = nil) ⇒ Object



6
7
8
9
# File 'lib/middleman-webpacked/command_runner.rb', line 6

def bin(path = nil)
  return @bin if path.nil?
  @bin = path
end

.mode(new_mode = nil) ⇒ Object



11
12
13
14
# File 'lib/middleman-webpacked/command_runner.rb', line 11

def mode(new_mode = nil)
  return @mode if new_mode.nil?
  @mode = new_mode if AVAILABLE_MODE.include?(new_mode)
end

.satisfy?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/middleman-webpacked/command_runner.rb', line 16

def satisfy?
  return false if bin.nil?
  File.exist?(bin)
end

Instance Method Details

#commandObject



48
49
50
51
52
53
54
55
56
# File 'lib/middleman-webpacked/command_runner.rb', line 48

def command
  [
    self.class.bin,
    "--mode #{self.class.mode}"
  ]
    .concat(entries)
    .concat(@arguments)
    .join(' ')
end

#entriesObject



42
43
44
45
46
# File 'lib/middleman-webpacked/command_runner.rb', line 42

def entries
  options.entry.map do |name, path|
    "--entry #{name}=./src/#{path}"
  end
end

#loadersObject



36
37
38
39
40
# File 'lib/middleman-webpacked/command_runner.rb', line 36

def loaders
  @loaders.map do |type, loader|
    "--module-bind #{type}=#{loader}-loader"
  end
end

#setupObject

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/middleman-webpacked/command_runner.rb', line 32

def setup
  raise NotImplementedError, "The command didn't setup for execute"
end