Class: Ghostest::TestCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/ghostest/test_condition.rb

Instance Method Summary collapse

Constructor Details

#initialize(language_klass) ⇒ TestCondition

Returns a new instance of TestCondition.



3
4
5
6
7
8
9
10
# File 'lib/ghostest/test_condition.rb', line 3

def initialize(language_klass)
  @language_klass = language_klass
  unless File.exist?(@language_klass.test_condition_yml_path)
    FileUtils.mkdir_p(File.dirname(@language_klass.test_condition_yml_path))
    File.write(@language_klass.test_condition_yml_path, YAML.dump({}))
  end
  @test_condition = YAML.load(File.read(@language_klass.test_condition_yml_path)) || {}
end

Instance Method Details

#save_as_updated!(source_path) ⇒ Object



12
13
14
15
16
17
# File 'lib/ghostest/test_condition.rb', line 12

def save_as_updated!(source_path)
  source_md5 = Digest::MD5.hexdigest(File.read(source_path))
  @test_condition[source_path] = { source_md5: }

  File.write(@language_klass.test_condition_yml_path, YAML.dump(@test_condition))
end

#should_update_test?(source_path) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/ghostest/test_condition.rb', line 19

def should_update_test?(source_path)
  source_md5 = Digest::MD5.hexdigest(File.read(source_path))
  @test_condition[source_path].nil? || @test_condition[source_path][:source_md5] != source_md5
end