Class: Ast::Crispr::DestinationProfile
- Inherits:
-
Object
- Object
- Ast::Crispr::DestinationProfile
- 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
-
#anchor_boundary ⇒ Object
readonly
Returns the value of attribute anchor_boundary.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#resolution_kind ⇒ Object
readonly
Returns the value of attribute resolution_kind.
-
#resolution_source ⇒ Object
readonly
Returns the value of attribute resolution_source.
Instance Method Summary collapse
- #anchor_boundary_family ⇒ Object
- #anchor_boundary_metadata ⇒ Object
- #anchored? ⇒ Boolean
- #append_fallback? ⇒ Boolean
- #callable_resolved? ⇒ Boolean
-
#initialize(resolution_kind:, resolution_source:, anchor_boundary:, used_if_missing: false, metadata: {}, **options) ⇒ DestinationProfile
constructor
A new instance of DestinationProfile.
- #known_anchor_boundary? ⇒ Boolean
- #known_resolution_kind? ⇒ Boolean
- #known_resolution_source? ⇒ Boolean
- #report ⇒ Object
- #resolution_family ⇒ Object
- #resolution_kind_metadata ⇒ Object
- #resolution_source_family ⇒ Object
- #resolution_source_metadata ⇒ Object
- #selector_resolved? ⇒ Boolean
- #to_h ⇒ Object
- #used_if_missing? ⇒ Boolean
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: {}, **) @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().freeze end |
Instance Attribute Details
#anchor_boundary ⇒ Object (readonly)
Returns the value of attribute anchor_boundary.
340 341 342 |
# File 'lib/ast/crispr.rb', line 340 def anchor_boundary @anchor_boundary end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
340 341 342 |
# File 'lib/ast/crispr.rb', line 340 def @metadata end |
#resolution_kind ⇒ Object (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_source ⇒ Object (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_family ⇒ Object
371 372 373 |
# File 'lib/ast/crispr.rb', line 371 def anchor_boundary_family &.fetch(:family, nil) end |
#anchor_boundary_metadata ⇒ Object
359 360 361 |
# File 'lib/ast/crispr.rb', line 359 def KNOWN_ANCHOR_BOUNDARIES[anchor_boundary]&.dup&.freeze end |
#anchored? ⇒ Boolean
391 392 393 |
# File 'lib/ast/crispr.rb', line 391 def anchored? resolution_kind == :anchor_after_statement end |
#append_fallback? ⇒ Boolean
387 388 389 |
# File 'lib/ast/crispr.rb', line 387 def append_fallback? resolution_kind == :append_fallback end |
#callable_resolved? ⇒ Boolean
395 396 397 |
# File 'lib/ast/crispr.rb', line 395 def callable_resolved? resolution_source == :callable end |
#known_anchor_boundary? ⇒ 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
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
379 380 381 |
# File 'lib/ast/crispr.rb', line 379 def known_resolution_source? KNOWN_RESOLUTION_SOURCES.key?(resolution_source) end |
#report ⇒ Object
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_family ⇒ Object
363 364 365 |
# File 'lib/ast/crispr.rb', line 363 def resolution_family &.fetch(:family, nil) end |
#resolution_kind_metadata ⇒ Object
351 352 353 |
# File 'lib/ast/crispr.rb', line 351 def KNOWN_RESOLUTION_KINDS[resolution_kind]&.dup&.freeze end |
#resolution_source_family ⇒ Object
367 368 369 |
# File 'lib/ast/crispr.rb', line 367 def resolution_source_family &.fetch(:family, nil) end |
#resolution_source_metadata ⇒ Object
355 356 357 |
# File 'lib/ast/crispr.rb', line 355 def KNOWN_RESOLUTION_SOURCES[resolution_source]&.dup&.freeze end |
#selector_resolved? ⇒ Boolean
399 400 401 |
# File 'lib/ast/crispr.rb', line 399 def selector_resolved? resolution_source == :selector end |
#to_h ⇒ Object
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
403 404 405 |
# File 'lib/ast/crispr.rb', line 403 def used_if_missing? @used_if_missing end |