Module: Foobara::InterpolatingGenerator

Defined in:
foobara-files-generator-0.2.4/src/interpolating_generator.rb

Instance Method Summary collapse

Instance Method Details

#end_marker ⇒ Object

Raises:

  • (NotImplementedError)


55
# File 'src/interpolating_generator.rb', line 55

def end_marker = raise NotImplementedError

#generate(_elements_to_generate) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'src/interpolating_generator.rb', line 3

def generate(_elements_to_generate)
  start_marker = self.start_marker
  end_marker = self.end_marker

  content = "#{start_marker}#{new_content}#{end_marker}"

  if File.exist?(template_path)
    match = insert_at&.match(target_contents)

    content = if match
                if match.captures.empty?
                  pre = match[0]
                  post = ""
                else
                  pre, *post = match.captures
                  post = post.join
                end

                "#{match.pre_match}#{pre}#{content}#{post}#{match.post_match}"
              else
                "#{target_contents}#{content}"
              end
  else
    match = /\A\n+/.match(content)

    # simplecov:disable
    if match
      # simplecov:enable
      newline_count = match[0].size
      start_marker = start_marker[newline_count..]
      content = match.post_match
    end

    match = /\n+\z/.match(content)

    # simplecov:disable
    if match
      # simplecov:enable
      newline_count = match[0].size
      end_marker = end_marker[...-newline_count]
      content = match.pre_match
    end

    content = "#{content}\n"
  end

  { content:, start_marker:, end_marker: }
end

#insert_at ⇒ Object



53
# File 'src/interpolating_generator.rb', line 53

def insert_at = nil

#new_content ⇒ Object

Raises:

  • (NotImplementedError)


52
# File 'src/interpolating_generator.rb', line 52

def new_content = raise NotImplementedError

#start_marker ⇒ Object

Raises:

  • (NotImplementedError)


54
# File 'src/interpolating_generator.rb', line 54

def start_marker = raise NotImplementedError