4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/generators/module_helper.rb', line 4
def module_generator_file_insert(file_path, options = {})
insert_file = File.read(file_path)
matcher_regex = options[:regex] || /path 'modules' do(.*)end/m
existing_entries = insert_file.match(matcher_regex).to_s.split("\n")
existing_entries.pop
existing_entries.shift
new_entry = options[:new_entry]
existing_entries.each do |entry|
if options[:insert_matcher] < entry.strip
insert_into_file file_path, new_entry.to_s, before: entry.to_s
return true
end
end
end
|