Class: Ast::Crispr::DocumentContext
- Inherits:
-
Object
- Object
- Ast::Crispr::DocumentContext
- Defined in:
- lib/ast/crispr.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#source_label ⇒ Object
readonly
Returns the value of attribute source_label.
Instance Method Summary collapse
- #ast ⇒ Object
- #comment_region_text(comment_region) ⇒ Object
- #comment_regions_for(owner, region: :leading, owner_scope: :shared_default) ⇒ Object
- #expand_following_gap(line_number) ⇒ Object
-
#initialize(content:, source_label: 'source', adapter: Adapters::Null.new, metadata: {}, **options) ⇒ DocumentContext
constructor
A new instance of DocumentContext.
- #line_blank?(line_number) ⇒ Boolean
- #lines ⇒ Object
- #location_slice(location) ⇒ Object
- #structural_owners(owner_scope: :shared_default) ⇒ Object
- #structure_profile(owner_scope: :shared_default) ⇒ Object
Constructor Details
#initialize(content:, source_label: 'source', adapter: Adapters::Null.new, metadata: {}, **options) ⇒ DocumentContext
Returns a new instance of DocumentContext.
717 718 719 720 721 722 |
# File 'lib/ast/crispr.rb', line 717 def initialize(content:, source_label: 'source', adapter: Adapters::Null.new, metadata: {}, **) @content = content.to_s @source_label = source_label @adapter = adapter @metadata = .merge() end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
715 716 717 |
# File 'lib/ast/crispr.rb', line 715 def adapter @adapter end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
715 716 717 |
# File 'lib/ast/crispr.rb', line 715 def content @content end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
715 716 717 |
# File 'lib/ast/crispr.rb', line 715 def @metadata end |
#source_label ⇒ Object (readonly)
Returns the value of attribute source_label.
715 716 717 |
# File 'lib/ast/crispr.rb', line 715 def source_label @source_label end |
Instance Method Details
#ast ⇒ Object
728 729 730 |
# File 'lib/ast/crispr.rb', line 728 def ast @ast ||= adapter.read_ast(self) end |
#comment_region_text(comment_region) ⇒ Object
740 741 742 |
# File 'lib/ast/crispr.rb', line 740 def comment_region_text(comment_region) adapter.comment_region_text(self, comment_region) end |
#comment_regions_for(owner, region: :leading, owner_scope: :shared_default) ⇒ Object
736 737 738 |
# File 'lib/ast/crispr.rb', line 736 def comment_regions_for(owner, region: :leading, owner_scope: :shared_default) adapter.comment_regions_for(self, owner, region: region, owner_scope: owner_scope) end |
#expand_following_gap(line_number) ⇒ Object
760 761 762 763 764 |
# File 'lib/ast/crispr.rb', line 760 def (line_number) last_line = line_number last_line += 1 while line_blank?(last_line + 1) last_line end |
#line_blank?(line_number) ⇒ Boolean
766 767 768 769 |
# File 'lib/ast/crispr.rb', line 766 def line_blank?(line_number) line = lines[line_number - 1] !line.nil? && line.strip.empty? end |
#lines ⇒ Object
724 725 726 |
# File 'lib/ast/crispr.rb', line 724 def lines @lines ||= content.lines end |
#location_slice(location) ⇒ Object
756 757 758 |
# File 'lib/ast/crispr.rb', line 756 def location_slice(location) content.byteslice(location.start_offset...location.end_offset).to_s end |
#structural_owners(owner_scope: :shared_default) ⇒ Object
732 733 734 |
# File 'lib/ast/crispr.rb', line 732 def structural_owners(owner_scope: :shared_default) adapter.structural_owners(self, owner_scope: owner_scope) end |
#structure_profile(owner_scope: :shared_default) ⇒ Object
744 745 746 747 748 749 750 751 752 753 754 |
# File 'lib/ast/crispr.rb', line 744 def structure_profile(owner_scope: :shared_default) if adapter.respond_to?(:structure_profile) adapter.structure_profile(owner_scope: owner_scope) else StructureProfile.new( owner_scope: owner_scope, owner_selector: owner_scope, metadata: { source: :document_context_default } ) end end |