Class: DeltaTest::Configuration
- Inherits:
-
Object
- Object
- DeltaTest::Configuration
- 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
-
#auto_configure! ⇒ Object
Auto configuration ———————————————–.
-
#base_path=(path) ⇒ Pathname
Override setters ———————————————–.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#load_from_file! ⇒ Object
Load configuration file And update ‘base_path` to the directory.
-
#precalculate! ⇒ Object
Precalculate some values.
-
#retrive_files_from_git_index! ⇒ Object
Retrive files from git index And update ‘files`.
-
#stats_path=(path) ⇒ Pathname
Store stats_path as Pathname.
-
#tmp_table_file ⇒ Pathname
Getters ———————————————–.
-
#update(validate: true) {|_self| ... } ⇒ Object
Update ———————————————–.
Methods included from Validator
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/delta_test/configuration.rb', line 111 def initialize update(validate: false) do |c| c.base_path = File.('.') c.stats_path = File.('tmp/delta_test_stats') c.stats_life = 1000 # commits c.files = [] c.patterns = [] c.exclude_patterns = [] c.full_test_patterns = [] c.custom_mappings = {} end end |
Instance Method Details
#auto_configure! ⇒ Object
Auto configuration
Use configuration file and git
183 184 185 186 187 |
# File 'lib/delta_test/configuration.rb', line 183 def auto_configure! load_from_file! retrive_files_from_git_index! update end |
#base_path=(path) ⇒ Pathname
Override setters
Store base_path as Pathname
135 136 137 138 |
# File 'lib/delta_test/configuration.rb', line 135 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
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/delta_test/configuration.rb', line 193 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
168 169 170 171 172 173 174 175 |
# File 'lib/delta_test/configuration.rb', line 168 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`
222 223 224 |
# File 'lib/delta_test/configuration.rb', line 222 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
146 147 148 149 |
# File 'lib/delta_test/configuration.rb', line 146 def stats_path=(path) return unless path @stats_path = Pathname.new(path) end |
#tmp_table_file ⇒ Pathname
Getters
Temporary table file path
234 235 236 |
# File 'lib/delta_test/configuration.rb', line 234 def tmp_table_file self.stats_path.join('tmp', DeltaTest.tester_id) end |
#update(validate: true) {|_self| ... } ⇒ Object
Update
Update, verify and precalculate
159 160 161 162 163 |
# File 'lib/delta_test/configuration.rb', line 159 def update(validate: true) yield self if block_given? validate! if validate precalculate! end |