speculate_about 1.0.5 → 1.0.6

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: 3fbc552a8595414d6e1b7dbbe3db1ccd402a641994525e03c80d0ce012b26f61
4
- data.tar.gz: 3bad757b061a13ee60055cdda247fb52becf060b5b2a039e6baf1e8ff6901b7d
3
+ metadata.gz: d5fd5bedf8d21cdc315dfbb8b3c24b22bc9956f1bfb0c08008902aecb9c83771
4
+ data.tar.gz: 141662a9daae3a23c62926d77cdc42d728d6108f36815ce169c183f0c9ae2ddc
5
5
  SHA512:
6
- metadata.gz: a782e9265dc4c020a49fe602662934fc13bbcffd8c3b101f91f1e3298bfaa66f87c2e215607ec6e59545b8a6a5fb463a5139ec23f019446fd2d2d31057de5d8e
7
- data.tar.gz: 5bf85f65b7797da2a3a02e446c2515849d912a1e049166ee32e6c7e1711287694e0f11eaa5c51d3c4545d67314b1b750b90c72f650263a2321f9a252b8c4bf48
6
+ metadata.gz: c7a0573301627f5bb460368e2034cf8355985055bbbaa6ba8e61740d6483248335d496d5ad7c309656a5e7d75f695c908044fccb047ce82cd264566c22376097
7
+ data.tar.gz: 53d9e35f85b1382bd00edc134ccf06e108c8e23127cc544ca415e3b22acb0837f71134b163b7800fad555b0096fcecaf25d0d81ae6d53a69c5367093a5344c34
@@ -2,6 +2,8 @@
2
2
  module Speculations
3
3
  module CLI extend self
4
4
  def run args
5
+ debug = false
6
+ force = false
5
7
  loop do
6
8
  case args.first
7
9
  when "-h", "--help"
@@ -9,20 +11,24 @@ module Speculations
9
11
  when "-v", "--version"
10
12
  _version
11
13
  when "-d", "--debug"
12
- return _compile_and_maybe_run(args.drop(1), debug: true)
14
+ debug = true
15
+ args = args.drop(1)
16
+ when "-f", "--force"
17
+ force = true
18
+ args = args.drop(1)
13
19
  else
14
- return _compile_and_maybe_run args
20
+ return _compile_and_maybe_run(args, debug:, force:)
15
21
  end
16
22
  end
17
23
  end
18
24
 
19
25
  private
20
26
 
21
- def _compile_and_maybe_run(args, debug: false)
27
+ def _compile_and_maybe_run(args, debug:, force:)
22
28
  require_relative "../speculations"
23
29
  args = Dir.glob(["*.md", "speculations/**/*.md"]) if args.empty?
24
30
  args.each do |input_file|
25
- Speculations.compile(input_file, debug:)
31
+ Speculations.compile(input_file, debug:, force:)
26
32
  end
27
33
  end
28
34
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Speculations
4
- VERSION = "1.0.5"
4
+ VERSION = "1.0.6"
5
5
  end
6
6
  # SPDX-License-Identifier: AGPL-3.0-or-later
data/lib/speculations.rb CHANGED
@@ -3,24 +3,24 @@ require_relative 'debugging'
3
3
  require_relative 'speculations/parser'
4
4
  module Speculations extend self
5
5
 
6
- DISCLAIMER = <<-EOD
6
+ DISCLAIMER = <<-EOD
7
7
  # DO NOT EDIT!!!
8
8
  # This file was generated from FILENAME with the speculate_about gem, if you modify this file
9
9
  # one of two bad things will happen
10
10
  # - your documentation specs are not correct
11
11
  # - your modifications will be overwritten by the speculate command line
12
12
  # YOU HAVE BEEN WARNED
13
- EOD
13
+ EOD
14
14
 
15
- def compile(infile, outfile=nil, debug: false)
15
+ def compile(infile, outfile=nil, debug: false, force: false)
16
16
  raise ArgumentError, "#{infile} not found" unless File.readable? infile
17
17
  outfile ||= _speculation_path(infile)
18
18
  if _out_of_date?(outfile, infile)
19
19
  debug__(msg: "recompiling #{infile} -> #{outfile}", debug:)
20
-
21
- ast = Speculations::Parser.new.parse_from_file(infile, debug:)
22
- code = _decorated_ast_code ast, infile
23
- File.write(outfile, code.join("\n"))
20
+ _compile(infile:, outfile:, debug:)
21
+ elsif force
22
+ debug__(msg: "*** forced recompilation #{infile} -> #{outfile}", debug:)
23
+ _compile(infile:, outfile:, debug:)
24
24
  else
25
25
  debug__(msg: "#{infile} ignored as it is upto date", debug:)
26
26
  end
@@ -29,9 +29,15 @@ module Speculations extend self
29
29
 
30
30
  private
31
31
 
32
+ def _compile(infile:, outfile:, debug:)
33
+ ast = Speculations::Parser.new.parse_from_file(infile, debug:)
34
+ code = _decorated_ast_code ast, infile
35
+ File.write(outfile, code.join("\n"))
36
+ end
37
+
32
38
  def _decorated_ast_code ast, filename
33
39
  [DISCLAIMER.gsub("FILENAME", filename.inspect).split("\n"), %{RSpec.describe #{filename.inspect} do}] +
34
- ast.to_code + ["end"]
40
+ ast.to_code + ["end"]
35
41
  end
36
42
 
37
43
  def _out_of_date?(outf, inf)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speculate_about
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-22 00:00:00.000000000 Z
11
+ date: 2024-04-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Allows Markdown or other text files to be used as literal specs, à la
14
14
  Elixir doctest, but from any file.