speculate_about 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01f8a6b1bd4d875d642678f3587c58494d61280f9064debbac19b5b60c3da4ee
4
- data.tar.gz: 409f1b1d636138e95180144267eab84a81eee537734e0bc417ee4e0e7af579f0
3
+ metadata.gz: d6c603b51bd04471204c4584fb1697f5a27dd7b578abd012c805046e7d9a49dc
4
+ data.tar.gz: 82f31cc63352e6d3c380b860a40a1f84a2f133b7b4f8a391363176f57d808415
5
5
  SHA512:
6
- metadata.gz: ea0a3e7ec17457a6de3bbefe6cc01c4a99be7626ad87ff3c766a04e62795f0648048e5fea50a6d85f31be9b321a73b7296ffa1ff65bfb4dbb38a4670216d13ad
7
- data.tar.gz: 455a502c19ca76b5aa5ebf5ddabec69d435f4af28a00b3f96bc048c98b50b44d6b72646e2e2f39ca62f2d486b6b9b2b57880eed493d43cc43338a7ec19930469
6
+ metadata.gz: bd30e3a46232a0d38b0d0725aa89df98f7d724faef50e350e3bacf106c552e279569087b830f93a656015dca03f5fe1e0ff0c511484a2c12ac3331ebb8e5c51a
7
+ data.tar.gz: f48a6400a5bd1d6971780e5c8261d957b64af79c96baa544dd21b4050240343da77bc48141b4d0097da32ee4ee4ff5d065c7d3aa0df65584a71caf99b4724d09
@@ -5,15 +5,15 @@ require 'speculations/parser'
5
5
  module SpeculateAbout
6
6
  def speculate_about file
7
7
  path = _find_file(file, File.dirname( caller.first ))
8
- code = _compile path
8
+ code = _compile path, file
9
9
  ENV["SPECULATE_ABOUT_DEBUG"] ? puts(code) : instance_eval(code)
10
10
  end
11
11
 
12
12
 
13
13
  private
14
14
 
15
- def _compile path
16
- ast = Speculations::Parser.new.parse_from_file(path)
15
+ def _compile path, file
16
+ ast = Speculations::Parser.new.parse_from_file(path, file)
17
17
  ast.to_code
18
18
  end
19
19
  def _find_file file, local_path
@@ -3,7 +3,7 @@ class Speculations::Parser
3
3
  require_relative './parser/context'
4
4
  require_relative './parser/state'
5
5
 
6
- attr_reader :filename, :input, :root, :state
6
+ attr_reader :filename, :input, :orig_filename, :root, :state
7
7
 
8
8
  def self.parsers
9
9
  @__parsers__ ||= {
@@ -14,8 +14,9 @@ class Speculations::Parser
14
14
  }
15
15
  end
16
16
 
17
- def parse_from_file file
17
+ def parse_from_file file, orig_filename = nil
18
18
  @filename = file
19
+ @orig_filename = orig_filename || file
19
20
  @input = File
20
21
  .new(file)
21
22
  .each_line(chomp: true)
@@ -30,7 +31,7 @@ class Speculations::Parser
30
31
  end
31
32
 
32
33
  def parse!
33
- root = node = Context.new(name: "Speculations from #{@filename}", lnb: 0, filename: @filename, parent: nil)
34
+ root = node = Context.new(name: "Speculations from #{@filename}", lnb: 0, filename: @filename, orig_filename: orig_filename, parent: nil)
34
35
  input.each_with_index do |line, lnb|
35
36
  @state, node = self.class.parsers.fetch(@state).parse(line, lnb.succ, node)
36
37
  end
@@ -3,7 +3,7 @@ class Speculations::Parser::Context
3
3
  require_relative './context/example'
4
4
  require_relative './context/setup'
5
5
 
6
- attr_reader :filename, :level, :lnb, :name, :parent, :setup
6
+ attr_reader :filename, :level, :lnb, :name, :orig_filename, :parent, :setup
7
7
 
8
8
  def add_child(name:, lnb:)
9
9
  raise "Illegal nesting" if parent
@@ -55,21 +55,22 @@ class Speculations::Parser::Context
55
55
 
56
56
  private
57
57
 
58
- def initialize(lnb:, name:, filename: nil, parent: nil)
59
- _init_from_parent filename, parent
60
- @level = parent ? parent.level.succ : 1
61
- @lnb = lnb
62
- @setup = nil
63
- @name = name
64
- @parent = parent
58
+ def initialize(lnb:, name:, filename: nil, orig_filename: nil, parent: nil)
59
+ _init_from_parent filename, orig_filename, parent
60
+ @level = parent ? parent.level.succ : 1
61
+ @lnb = lnb
62
+ @setup = nil
63
+ @name = name
64
+ @parent = parent
65
65
  end
66
66
 
67
67
  def _header
68
68
  map_lines(%{context "#{name}" do}, indent: -1)
69
69
  end
70
70
 
71
- def _init_from_parent filename, parent
71
+ def _init_from_parent filename, orig_filename, parent
72
72
  @filename = parent ? parent.filename : filename
73
+ @orig_filename = parent ? parent.orig_filename : orig_filename
73
74
  raise ArgumentError, "no filename given in root context" unless @filename
74
75
  end
75
76
 
@@ -34,9 +34,9 @@ class Speculations::Parser::Context::Example
34
34
  _, name = NAMED_EXAMPLE.match(line).to_a
35
35
 
36
36
  if name&.empty? == false # SIC
37
- "#{name} (#{File.basename(parent.filename)}:#{lnb.succ})"
37
+ "#{name} (#{parent.orig_filename}:#{lnb.succ})"
38
38
  else
39
- "Example from #{parent.filename}:#{lnb.succ}"
39
+ "Example from #{parent.orig_filename}:#{lnb.succ}"
40
40
  end
41
41
  end
42
42
 
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: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-02 00:00:00.000000000 Z
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec