Class: NewlineHw::Shell::Runners::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/newline_hw/shell/runners/base.rb

Direct Known Subclasses

Javascript, Ruby

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pwd) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/newline_hw/shell/runners/base.rb', line 7

def initialize(pwd)
  @commands = []
  @pwd = pwd
  prepare_commands
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



5
6
7
# File 'lib/newline_hw/shell/runners/base.rb', line 5

def commands
  @commands
end

#pwdObject (readonly)

Returns the value of attribute pwd.



5
6
7
# File 'lib/newline_hw/shell/runners/base.rb', line 5

def pwd
  @pwd
end

Class Method Details

.get_commands(pwd) ⇒ Object



34
35
36
# File 'lib/newline_hw/shell/runners/base.rb', line 34

def self.get_commands(pwd)
  new(pwd).commands
end

Instance Method Details

#add_command(cmd) ⇒ Object



13
14
15
# File 'lib/newline_hw/shell/runners/base.rb', line 13

def add_command(cmd)
  @commands << cmd
end

#file?(*args) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/newline_hw/shell/runners/base.rb', line 21

def file?(*args)
  File.exist?(file_path(*args))
end

#file_contents?(regex, *args) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/newline_hw/shell/runners/base.rb', line 25

def file_contents?(regex, *args)
  return false unless file?(*args)
  !File.readlines(file_path(*args)).grep(regex).empty?
end

#file_path(*args) ⇒ Object



17
18
19
# File 'lib/newline_hw/shell/runners/base.rb', line 17

def file_path(*args)
  File.expand_path(File.join(pwd, *args))
end

#prepare_commandsObject

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/newline_hw/shell/runners/base.rb', line 30

def prepare_commands
  raise NotImplementedError, "Subclases of Tiyo::Runners::Base must implement prepare_commands"
end