abide_dev_utils 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa840c23e0e5ab5d978e04b6c3192bd473fa7d3886033be49c20124f33964c8b
4
- data.tar.gz: 6d8d44b81c393907052d1cd70907b31e8e339ee7519080152ba3f2b5da3cd420
3
+ metadata.gz: 54b60da7a8a67908351bf5e2687c39e8ac76aad00cb71ad798ac0c0a195e07fe
4
+ data.tar.gz: 400a2593d83b24a0f970a52f4b6ae0434ff41975260b351c5dd5d0e52387f282
5
5
  SHA512:
6
- metadata.gz: b18c4a042ae47492d235a3778f3b50a3589940af256cd0407ea38c170766fcaade5d8ead74c9baa47490c407bc9c375703356640e8f1e393a230055ddd099798
7
- data.tar.gz: c2578428399f77596809838daa1adae12aa76e0f34298c3695bd9058a9da1a6c6e3a4e9120542dad9a6b2eda473581196e40df3467a8ff706332ce52824f2707
6
+ metadata.gz: 3857661d49e0fd254fda83c58ac0363cad5df50342aa55eca44f05f8e1dd47214200ef8586bbec6c1f46767cd7d0528be8f089507e0a6699896971ffceaca2da
7
+ data.tar.gz: edaa3a7dc991292d51feba476cd49cf343e570ac87e0310957f4d55d43932fd3dc4ed6d72aa6f78fbc686063416e65ed0bbed03bf550fffcf63a135c3175d4af
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abide_dev_utils (0.14.0)
4
+ abide_dev_utils (0.14.1)
5
5
  amatch (~> 0.4)
6
6
  cmdparse (~> 3.0)
7
7
  facterdb (>= 1.21)
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tempfile'
4
+ require 'fileutils'
5
+
3
6
  module AbideDevUtils
4
7
  # Formats text for output in markdown
5
8
  class Markdown
@@ -14,11 +17,17 @@ module AbideDevUtils
14
17
  def to_markdown
15
18
  toc = @toc.join("\n")
16
19
  body = @body.join("\n")
17
- "#{@title}\n#{toc}\n\n#{body}"
20
+ "#{@title}\n#{toc}\n\n#{body}".encode(universal_newline: true)
18
21
  end
22
+ alias to_s to_markdown
19
23
 
20
24
  def to_file
21
- File.write(@file, to_markdown)
25
+ this_markdown = to_markdown
26
+ Tempfile.create('markdown') do |f|
27
+ f.write(this_markdown)
28
+ check_file_content(f.path, this_markdown)
29
+ FileUtils.mv(f.path, @file)
30
+ end
22
31
  end
23
32
 
24
33
  def method_missing(name, *args, &block)
@@ -88,6 +97,14 @@ module AbideDevUtils
88
97
 
89
98
  private
90
99
 
100
+ def check_file_content(file, content)
101
+ raise "File #{file} not found! Not saving to #{@file}" unless File.exist?(file)
102
+ raise "File #{file} is empty! Not saving to #{@file}" if File.zero?(file)
103
+ return if File.read(file).include?(content)
104
+
105
+ raise "File #{file} does not contain correct content! Not saving to #{@file}"
106
+ end
107
+
91
108
  def add(type, text, *args, **kwargs)
92
109
  @toc << ul(link(text, text, anchor: true), indent: 0) if @with_toc && type == :h1
93
110
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AbideDevUtils
4
- VERSION = "0.14.0"
4
+ VERSION = "0.14.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abide_dev_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - abide-team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
11
+ date: 2023-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri