Class: Ast::Crispr::DestinationProfile

Inherits:
Object
  • Object
show all
Includes:
ProfileReportCompatibility
Defined in:
lib/ast/crispr.rb,
lib/ast/crispr.rb

Constant Summary collapse

KNOWN_RESOLUTION_KINDS =
{
  append_fallback: {
    family: :append,
    description: 'Insertion fell back to appending at the end of the document'
  },
  anchor_after_statement: {
    family: :anchored,
    description: 'Insertion resolved a statement anchor and spliced after it'
  }
}.freeze
KNOWN_RESOLUTION_SOURCES =
{
  none: {
    family: :implicit,
    description: 'No destination object was provided'
  },
  callable: {
    family: :callable,
    description: 'Destination was resolved from a callable'
  },
  selector: {
    family: :selector,
    description: 'Destination was resolved from an owner selector anchor'
  }
}.freeze
KNOWN_ANCHOR_BOUNDARIES =
{
  none: {
    family: :none,
    description: 'No anchor boundary was used'
  },
  statement_end_plus_following_gap: {
    family: :gap_preserving_statement,
    description: 'Insertion anchored after a statement and preserved its following blank-line gap'
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resolution_kind:, resolution_source:, anchor_boundary:, used_if_missing: false, metadata: {}, **options) ⇒ DestinationProfile

Returns a new instance of DestinationProfile.



342
343
344
345
346
347
348
349
# File 'lib/ast/crispr.rb', line 342

def initialize(resolution_kind:, resolution_source:, anchor_boundary:, used_if_missing: false, metadata: {},
               **options)
  @resolution_kind = normalize_resolution_kind(resolution_kind)
  @resolution_source = normalize_resolution_source(resolution_source)
  @anchor_boundary = normalize_anchor_boundary(anchor_boundary)
  @used_if_missing = used_if_missing ? true : false
  @metadata = .merge(options).freeze
end

Instance Attribute Details

#anchor_boundaryObject (readonly)

Returns the value of attribute anchor_boundary.



340
341
342
# File 'lib/ast/crispr.rb', line 340

def anchor_boundary
  @anchor_boundary
end

#metadataObject (readonly)

Returns the value of attribute metadata.



340
341
342
# File 'lib/ast/crispr.rb', line 340

def 
  @metadata
end

#resolution_kindObject (readonly)

Returns the value of attribute resolution_kind.



340
341
342
# File 'lib/ast/crispr.rb', line 340

def resolution_kind
  @resolution_kind
end

#resolution_sourceObject (readonly)

Returns the value of attribute resolution_source.



340
341
342
# File 'lib/ast/crispr.rb', line 340

def resolution_source
  @resolution_source
end

Instance Method Details

#anchor_boundary_familyObject



371
372
373
# File 'lib/ast/crispr.rb', line 371

def anchor_boundary_family
  &.fetch(:family, nil)
end

#anchor_boundary_metadataObject



359
360
361
# File 'lib/ast/crispr.rb', line 359

def 
  KNOWN_ANCHOR_BOUNDARIES[anchor_boundary]&.dup&.freeze
end

#anchored?Boolean

Returns:

  • (Boolean)


391
392
393
# File 'lib/ast/crispr.rb', line 391

def anchored?
  resolution_kind == :anchor_after_statement
end

#append_fallback?Boolean

Returns:

  • (Boolean)


387
388
389
# File 'lib/ast/crispr.rb', line 387

def append_fallback?
  resolution_kind == :append_fallback
end

#callable_resolved?Boolean

Returns:

  • (Boolean)


395
396
397
# File 'lib/ast/crispr.rb', line 395

def callable_resolved?
  resolution_source == :callable
end

#known_anchor_boundary?Boolean

Returns:

  • (Boolean)


383
384
385
# File 'lib/ast/crispr.rb', line 383

def known_anchor_boundary?
  KNOWN_ANCHOR_BOUNDARIES.key?(anchor_boundary)
end

#known_resolution_kind?Boolean

Returns:

  • (Boolean)


375
376
377
# File 'lib/ast/crispr.rb', line 375

def known_resolution_kind?
  KNOWN_RESOLUTION_KINDS.key?(resolution_kind)
end

#known_resolution_source?Boolean

Returns:

  • (Boolean)


379
380
381
# File 'lib/ast/crispr.rb', line 379

def known_resolution_source?
  KNOWN_RESOLUTION_SOURCES.key?(resolution_source)
end

#reportObject



1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
# File 'lib/ast/crispr.rb', line 1645

def report
  data = to_h.merge(
    known_resolution_kind: KNOWN_RESOLUTION_KINDS.key?(resolution_kind),
    known_resolution_source: KNOWN_RESOLUTION_SOURCES.key?(resolution_source),
    resolution_family: resolution_family || :unknown,
    resolution_source_family: resolution_source_family || :unknown,
    anchor_boundary_family: anchor_boundary_family || :unknown
  )
  stringified_report(data)
end

#resolution_familyObject



363
364
365
# File 'lib/ast/crispr.rb', line 363

def resolution_family
  &.fetch(:family, nil)
end

#resolution_kind_metadataObject



351
352
353
# File 'lib/ast/crispr.rb', line 351

def 
  KNOWN_RESOLUTION_KINDS[resolution_kind]&.dup&.freeze
end

#resolution_source_familyObject



367
368
369
# File 'lib/ast/crispr.rb', line 367

def resolution_source_family
  &.fetch(:family, nil)
end

#resolution_source_metadataObject



355
356
357
# File 'lib/ast/crispr.rb', line 355

def 
  KNOWN_RESOLUTION_SOURCES[resolution_source]&.dup&.freeze
end

#selector_resolved?Boolean

Returns:

  • (Boolean)


399
400
401
# File 'lib/ast/crispr.rb', line 399

def selector_resolved?
  resolution_source == :selector
end

#to_hObject



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/ast/crispr.rb', line 407

def to_h
  {
    resolution_kind: resolution_kind,
    resolution_family: resolution_family,
    known_resolution_kind: known_resolution_kind?,
    resolution_source: resolution_source,
    resolution_source_family: resolution_source_family,
    known_resolution_source: known_resolution_source?,
    anchor_boundary: anchor_boundary,
    anchor_boundary_family: anchor_boundary_family,
    known_anchor_boundary: known_anchor_boundary?,
    used_if_missing: used_if_missing?,
    append_fallback: append_fallback?,
    anchored: anchored?,
    metadata: 
  }
end

#used_if_missing?Boolean

Returns:

  • (Boolean)


403
404
405
# File 'lib/ast/crispr.rb', line 403

def used_if_missing?
  @used_if_missing
end