Class: PlatformosCheck::GraphqlFile

Inherits:
AppFile
  • Object
show all
Defined in:
lib/platformos_check/graphql_file.rb

Constant Summary collapse

DIR_PREFIX =
%r{\A/?((marketplace_builder|app)/(graph_queries|graphql)s?/|modules/((\w|-)*)/(private|public)/(graph_queries|graphql)s?/)}

Instance Attribute Summary

Attributes inherited from AppFile

#storage, #version

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AppFile

#==, #build_name, #initialize, #liquid?, #module_name, #name, #path, #relative_path, #remove_extension, #source, #yaml?

Constructor Details

This class inherits a constructor from PlatformosCheck::AppFile

Class Method Details

.parse(_source) ⇒ Object



58
59
60
# File 'lib/platformos_check/graphql_file.rb', line 58

def self.parse(_source)
  Struct.new(:warnings, :root)
end

Instance Method Details

#dir_prefixObject



22
23
24
# File 'lib/platformos_check/graphql_file.rb', line 22

def dir_prefix
  DIR_PREFIX
end

#parseObject



46
47
48
# File 'lib/platformos_check/graphql_file.rb', line 46

def parse
  @parse ||= GraphQL.parse(source)
end

#rewriterObject



18
19
20
# File 'lib/platformos_check/graphql_file.rb', line 18

def rewriter
  @rewriter ||= AppFileRewriter.new(@relative_path, source)
end

#rootObject



54
55
56
# File 'lib/platformos_check/graphql_file.rb', line 54

def root
  parse.root
end

#source_excerpt(line) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/platformos_check/graphql_file.rb', line 26

def source_excerpt(line)
  original_lines = source.split("\n")
  original_lines[bounded(0, line - 1, original_lines.size - 1)].strip
rescue StandardError => e
  PlatformosCheck.bug(<<~EOS)
    Exception while running `source_excerpt(#{line})`:
    ```
    #{e.class}: #{e.message}
      #{e.backtrace.join("\n  ")}
    ```

    path: #{path}

    source:
    ```
    #{source}
    ```
  EOS
end

#warningsObject



50
51
52
# File 'lib/platformos_check/graphql_file.rb', line 50

def warnings
  @ast.warnings
end

#writeObject



9
10
11
12
13
14
15
16
# File 'lib/platformos_check/graphql_file.rb', line 9

def write
  content = rewriter.to_s
  return unless source != content

  @storage.write(@relative_path, content.gsub("\n", @eol))
  @source = content
  @rewriter = nil
end