Class: Crystalball::Rails::Predictor::ModifiedSchema
- Inherits:
-
Object
- Object
- Crystalball::Rails::Predictor::ModifiedSchema
- Defined in:
- lib/crystalball/rails/predictor/modified_schema.rb
Overview
Used with ‘predictor.use Crystalball::Rails::Predictor::ModifiedSchema.new(tables_map_path:)`. When used will check db/schema.rb for changes and add specs which depend on files affected by changed tables
Constant Summary collapse
- SCHEMA_PATH =
'db/schema.rb'
Instance Attribute Summary collapse
-
#tables_map_path ⇒ Object
readonly
Returns the value of attribute tables_map_path.
Instance Method Summary collapse
-
#call(diff, map) ⇒ Array<String>
The spec paths associated with the changes.
-
#initialize(tables_map_path:) ⇒ ModifiedSchema
constructor
A new instance of ModifiedSchema.
- #tables_map ⇒ Crystalball::Rails::TablesMap
Methods included from Predictor::Helpers::AffectedExampleGroupsDetector
Constructor Details
#initialize(tables_map_path:) ⇒ ModifiedSchema
Returns a new instance of ModifiedSchema.
19 20 21 |
# File 'lib/crystalball/rails/predictor/modified_schema.rb', line 19 def initialize(tables_map_path:) @tables_map_path = tables_map_path end |
Instance Attribute Details
#tables_map_path ⇒ Object (readonly)
Returns the value of attribute tables_map_path.
16 17 18 |
# File 'lib/crystalball/rails/predictor/modified_schema.rb', line 16 def tables_map_path @tables_map_path end |
Instance Method Details
#call(diff, map) ⇒ Array<String>
Returns the spec paths associated with the changes.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/crystalball/rails/predictor/modified_schema.rb', line 28 def call(diff, map) return [] if schema_diff(diff).nil? old_schema = old_schema(diff) new_schema = new_schema(diff) changed_tables = changed_tables(old_schema, new_schema) files = changed_tables.flat_map do |table_name| files = tables_map[table_name] Crystalball.log :warn, "There are no model files for changed table `#{table_name}`. Check https://github.com/toptal/crystalball#warning for detailed description" unless files&.any? files end.compact detect_examples(files, map) end |
#tables_map ⇒ Crystalball::Rails::TablesMap
45 46 47 |
# File 'lib/crystalball/rails/predictor/modified_schema.rb', line 45 def tables_map @tables_map ||= MapStorage::YAMLStorage.load(Pathname(tables_map_path)) end |