Class: TiyoHw::Runners::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tiyo_hw/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.



6
7
8
9
10
# File 'lib/tiyo_hw/runners/base.rb', line 6

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

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



4
5
6
# File 'lib/tiyo_hw/runners/base.rb', line 4

def commands
  @commands
end

#pwdObject (readonly)

Returns the value of attribute pwd.



4
5
6
# File 'lib/tiyo_hw/runners/base.rb', line 4

def pwd
  @pwd
end

Class Method Details

.get_commands(pwd) ⇒ Object



32
33
34
# File 'lib/tiyo_hw/runners/base.rb', line 32

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

Instance Method Details

#add_command(cmd) ⇒ Object



12
13
14
# File 'lib/tiyo_hw/runners/base.rb', line 12

def add_command(cmd)
  @commands << cmd
end

#file?(*args) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/tiyo_hw/runners/base.rb', line 20

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

#file_contents?(regex, *args) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/tiyo_hw/runners/base.rb', line 24

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

#file_path(*args) ⇒ Object



16
17
18
# File 'lib/tiyo_hw/runners/base.rb', line 16

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

#prepare_commandsObject

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/tiyo_hw/runners/base.rb', line 28

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