Class: Querly::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/querly/script.rb

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, node:) ⇒ Script

Returns a new instance of Script.



16
17
18
19
# File 'lib/querly/script.rb', line 16

def initialize(path:, node:)
  @path = path
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



4
5
6
# File 'lib/querly/script.rb', line 4

def node
  @node
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/querly/script.rb', line 3

def path
  @path
end

Class Method Details

.load(path:, source:) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/querly/script.rb', line 6

def self.load(path:, source:)
  parser = Parser::Ruby25.new(Builder.new).tap do |parser|
    parser.diagnostics.all_errors_are_fatal = true
    parser.diagnostics.ignore_warnings = true
  end
  buffer = Parser::Source::Buffer.new(path.to_s, 1)
  buffer.source = source
  self.new(path: path, node: parser.parse(buffer))
end

Instance Method Details

#root_pairObject



21
22
23
# File 'lib/querly/script.rb', line 21

def root_pair
  NodePair.new(node: node)
end