Class: Sidenotes::Verifier
- Inherits:
-
Object
- Object
- Sidenotes::Verifier
- Defined in:
- lib/sidenotes/verifier.rb
Defined Under Namespace
Classes: Drift
Instance Attribute Summary collapse
-
#checked_count ⇒ Object
readonly
Returns the value of attribute checked_count.
-
#drifts ⇒ Object
readonly
Returns the value of attribute drifts.
-
#missing_sidecars ⇒ Object
readonly
Returns the value of attribute missing_sidecars.
-
#pending_migrations ⇒ Object
readonly
Returns the value of attribute pending_migrations.
Instance Method Summary collapse
- #check_pending_migrations ⇒ Object
- #drift? ⇒ Boolean
-
#initialize ⇒ Verifier
constructor
A new instance of Verifier.
- #issue_count ⇒ Object
- #pending_migrations? ⇒ Boolean
- #verify_all ⇒ Object
- #verify_model(model) ⇒ Object
Constructor Details
#initialize ⇒ Verifier
Returns a new instance of Verifier.
12 13 14 15 16 17 |
# File 'lib/sidenotes/verifier.rb', line 12 def initialize @drifts = [] @missing_sidecars = [] @checked_count = 0 @pending_migrations = [] end |
Instance Attribute Details
#checked_count ⇒ Object (readonly)
Returns the value of attribute checked_count.
10 11 12 |
# File 'lib/sidenotes/verifier.rb', line 10 def checked_count @checked_count end |
#drifts ⇒ Object (readonly)
Returns the value of attribute drifts.
10 11 12 |
# File 'lib/sidenotes/verifier.rb', line 10 def drifts @drifts end |
#missing_sidecars ⇒ Object (readonly)
Returns the value of attribute missing_sidecars.
10 11 12 |
# File 'lib/sidenotes/verifier.rb', line 10 def missing_sidecars @missing_sidecars end |
#pending_migrations ⇒ Object (readonly)
Returns the value of attribute pending_migrations.
10 11 12 |
# File 'lib/sidenotes/verifier.rb', line 10 def pending_migrations @pending_migrations end |
Instance Method Details
#check_pending_migrations ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sidenotes/verifier.rb', line 26 def check_pending_migrations context = migration_context return unless context.respond_to?(:pending_migrations) @pending_migrations = context.pending_migrations.map do |m| { 'version' => m.version, 'name' => m.name } end rescue StandardError => e warn "Sidenotes: could not check pending migrations: #{e.}" end |
#drift? ⇒ Boolean
62 63 64 |
# File 'lib/sidenotes/verifier.rb', line 62 def drift? drifts.any? || missing_sidecars.any? || pending_migrations? end |
#issue_count ⇒ Object
66 67 68 |
# File 'lib/sidenotes/verifier.rb', line 66 def issue_count drifts.sum { |d| d.issues.size } + missing_sidecars.size + pending_migrations.size end |
#pending_migrations? ⇒ Boolean
37 38 39 |
# File 'lib/sidenotes/verifier.rb', line 37 def pending_migrations? pending_migrations.any? end |
#verify_all ⇒ Object
19 20 21 22 23 24 |
# File 'lib/sidenotes/verifier.rb', line 19 def verify_all check_pending_migrations generator = Generator.new generator.discover_models.each { |model| verify_model(model) } self end |
#verify_model(model) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sidenotes/verifier.rb', line 41 def verify_model(model) inspector = ModelInspector.new(model) return unless inspector.inspectable? @checked_count += 1 sidecar = sidecar_path_for(model) unless File.exist?(sidecar) @missing_sidecars << model.name return end stored = parse_sidecar(sidecar, model.name) current = inspector.inspect_model issues = compare(stored, current) return if issues.empty? @drifts << Drift.new(model_name: model.name, sidecar_path: sidecar, issues: issues) end |