• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Nu-hin / remote_ruby / 13531045896

25 Feb 2025 09:12PM UTC coverage: 89.697%. Remained the same
13531045896

push

github

Nu-hin
Add plugins info to the Readme

888 of 990 relevant lines covered (89.7%)

59.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/remote_ruby/source_extractor.rb
1
# frozen_string_literal: true
2

3
require 'method_source'
16✔
4
require 'parser/current'
16✔
5
require 'unparser'
16✔
6

7
# Opt-in to most recent AST format
8
Parser::Builders::Default.emit_lambda              = true
16✔
9
Parser::Builders::Default.emit_procarg0            = true
16✔
10
Parser::Builders::Default.emit_encoding            = true
16✔
11
Parser::Builders::Default.emit_index               = true
16✔
12
Parser::Builders::Default.emit_arg_inside_procarg0 = true
16✔
13
Parser::Builders::Default.emit_forward_arg         = true
16✔
14
Parser::Builders::Default.emit_kwargs              = true
16✔
15
Parser::Builders::Default.emit_match_pattern       = true
16✔
16

17
module RemoteRuby
16✔
18
  # Receives a block and extracts Ruby code (as a string) with this block's
19
  # source
20
  class SourceExtractor
16✔
21
    def extract(&block)
16✔
22
      ast = Parser::CurrentRuby.parse(block.source)
304✔
23
      block_node = find_block(ast)
304✔
24

25
      return '' unless block_node
304✔
26

27
      _, body = parse(block_node)
304✔
28
      Unparser.unparse(body)
304✔
29
    end
30

31
    private
16✔
32

33
    def find_block(node)
16✔
34
      return nil unless node.is_a? AST::Node
688✔
35
      return node if node.type == :block
496✔
36

37
      node.children.each do |child|
192✔
38
        res = find_block(child)
384✔
39
        return res if res
384✔
40
      end
41

42
      nil
43
    end
44

45
    def parse(node)
16✔
46
      args = node.children[1].children
304✔
47
      body = node.children[2]
304✔
48
      [args, body]
304✔
49
    end
50
  end
51
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc