Class: DeltaTest::Configuration

Inherits:
Object
  • Object
show all
Includes:
Validator
Defined in:
lib/delta_test/configuration.rb

Defined Under Namespace

Modules: Validator

Constant Summary collapse

CONFIG_FILES =
[
  'delta_test.yml',
  'delta_test.yaml',
].map(&:freeze).freeze

Instance Method Summary collapse

Methods included from Validator

included

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/delta_test/configuration.rb', line 117

def initialize
  update(validate: false) do |c|
    c.base_path  = File.expand_path('.')
    c.stats_path = File.expand_path('tmp/delta_test_stats')
    c.stats_life = 1000  # commits

    c.files     = []

    c.full_test_patterns = []
    c.full_test_branches = []

    c.patterns           = []
    c.exclude_patterns   = []
    c.custom_mappings    = {}
  end
end

Instance Method Details

#auto_configure!Object

Auto configuration


Use configuration file and git



191
192
193
194
195
# File 'lib/delta_test/configuration.rb', line 191

def auto_configure!
  load_from_file!
  retrive_files_from_git_index!
  update
end

#base_path=(path) ⇒ Pathname

Override setters


Store base_path as Pathname

Returns:

  • (Pathname)


143
144
145
146
# File 'lib/delta_test/configuration.rb', line 143

def base_path=(path)
  return unless path
  @base_path = Pathname.new(path)
end

#load_from_file!Object

Load configuration file And update ‘base_path` to the directory



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/delta_test/configuration.rb', line 201

def load_from_file!
  config_file = Utils.find_file_upward(*CONFIG_FILES)

  unless config_file
    raise NoConfigurationFileFoundError
  end

  yaml = YAML.load_file(config_file)
  yaml_dir = File.dirname(config_file)

  _base_path = yaml.delete('base_path')
  self.base_path = _base_path ? File.absolute_path(_base_path, yaml_dir) : yaml_dir

  _stats_path = yaml.delete('stats_path')
  self.stats_path = File.absolute_path(_stats_path, yaml_dir) if _stats_path

  yaml.each do |k, v|
    if self.respond_to?("#{k}=")
      self.send("#{k}=", v)
    else
      raise InvalidOptionError.new(k)
    end
  end
end

#precalculate!Object

Precalculate some values



176
177
178
179
180
181
182
183
# File 'lib/delta_test/configuration.rb', line 176

def precalculate!
  filtered_files = self.files
    .map { |f| Utils.regulate_filepath(f, self.base_path) }
    .uniq
  @filtered_files = Utils.files_grep(filtered_files, self.patterns, self.exclude_patterns).to_set

  @stats_path = Pathname.new(File.absolute_path(self.stats_path, self.base_path))
end

#retrive_files_from_git_index!Object

Retrive files from git index And update ‘files`



230
231
232
# File 'lib/delta_test/configuration.rb', line 230

def retrive_files_from_git_index!
  self.files = Git.new(self.base_path).ls_files
end

#stats_path=(path) ⇒ Pathname

Store stats_path as Pathname

Returns:

  • (Pathname)


154
155
156
157
# File 'lib/delta_test/configuration.rb', line 154

def stats_path=(path)
  return unless path
  @stats_path = Pathname.new(path)
end

#tmp_table_filePathname

Getters


Temporary table file path

Returns:

  • (Pathname)


242
243
244
# File 'lib/delta_test/configuration.rb', line 242

def tmp_table_file
  self.stats_path.join('tmp', DeltaTest.tester_id)
end

#update(validate: true) {|_self| ... } ⇒ Object

Update


Update, verify and precalculate

Yields:

  • (_self)

Yield Parameters:



167
168
169
170
171
# File 'lib/delta_test/configuration.rb', line 167

def update(validate: true)
  yield self if block_given?
  validate! if validate
  precalculate!
end