speculate_about 0.1.0 → 0.1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01f8a6b1bd4d875d642678f3587c58494d61280f9064debbac19b5b60c3da4ee
|
4
|
+
data.tar.gz: 409f1b1d636138e95180144267eab84a81eee537734e0bc417ee4e0e7af579f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea0a3e7ec17457a6de3bbefe6cc01c4a99be7626ad87ff3c766a04e62795f0648048e5fea50a6d85f31be9b321a73b7296ffa1ff65bfb4dbb38a4670216d13ad
|
7
|
+
data.tar.gz: 455a502c19ca76b5aa5ebf5ddabec69d435f4af28a00b3f96bc048c98b50b44d6b72646e2e2f39ca62f2d486b6b9b2b57880eed493d43cc43338a7ec19930469
|
data/lib/speculate_about.rb
CHANGED
@@ -4,7 +4,7 @@ require 'speculations/parser'
|
|
4
4
|
|
5
5
|
module SpeculateAbout
|
6
6
|
def speculate_about file
|
7
|
-
path = _find_file(file)
|
7
|
+
path = _find_file(file, File.dirname( caller.first ))
|
8
8
|
code = _compile path
|
9
9
|
ENV["SPECULATE_ABOUT_DEBUG"] ? puts(code) : instance_eval(code)
|
10
10
|
end
|
@@ -16,11 +16,11 @@ module SpeculateAbout
|
|
16
16
|
ast = Speculations::Parser.new.parse_from_file(path)
|
17
17
|
ast.to_code
|
18
18
|
end
|
19
|
-
def _find_file file
|
19
|
+
def _find_file file, local_path
|
20
20
|
return file if File.readable? file
|
21
|
-
|
22
|
-
return
|
23
|
-
raise ArgumentError, "file #{file}
|
21
|
+
local_file = File.join(local_path, file)
|
22
|
+
return local_file if File.readable? local_file
|
23
|
+
raise ArgumentError, "file #{file.inspect} not found"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -11,8 +11,8 @@ class Speculations::Parser::Context
|
|
11
11
|
children.last
|
12
12
|
end
|
13
13
|
|
14
|
-
def add_example(lnb:)
|
15
|
-
examples << Example.new(lnb: lnb, parent: self)
|
14
|
+
def add_example(lnb:, line:)
|
15
|
+
examples << Example.new(lnb: lnb, parent: self, line: line)
|
16
16
|
examples.last
|
17
17
|
end
|
18
18
|
|
@@ -2,6 +2,8 @@ class Speculations::Parser::Context::Example
|
|
2
2
|
|
3
3
|
attr_reader :lnb, :name, :parent
|
4
4
|
|
5
|
+
NAMED_EXAMPLE = %r{\A[`~]{3,}ruby\s+:example\s+(.*)}
|
6
|
+
|
5
7
|
def add_line line
|
6
8
|
lines << line
|
7
9
|
self
|
@@ -22,10 +24,20 @@ class Speculations::Parser::Context::Example
|
|
22
24
|
|
23
25
|
private
|
24
26
|
|
25
|
-
def initialize(lnb:, parent:)
|
27
|
+
def initialize(lnb:, line:, parent:)
|
26
28
|
@lnb = lnb
|
27
|
-
@name = "Example from #{parent.filename}:#{lnb.succ}"
|
28
29
|
@parent = parent
|
30
|
+
@name = _compute_name(lnb: lnb, line: line, parent: parent)
|
31
|
+
end
|
32
|
+
|
33
|
+
def _compute_name(lnb:, parent:, line:)
|
34
|
+
_, name = NAMED_EXAMPLE.match(line).to_a
|
35
|
+
|
36
|
+
if name&.empty? == false # SIC
|
37
|
+
"#{name} (#{File.basename(parent.filename)}:#{lnb.succ})"
|
38
|
+
else
|
39
|
+
"Example from #{parent.filename}:#{lnb.succ}"
|
40
|
+
end
|
29
41
|
end
|
30
42
|
|
31
43
|
def _example_head
|
@@ -13,7 +13,7 @@ module Speculations
|
|
13
13
|
node = node.set_setup(lnb: lnb)
|
14
14
|
[:bef, node]
|
15
15
|
when State.example_match(line)
|
16
|
-
node = node.add_example(lnb: lnb)
|
16
|
+
node = node.add_example(lnb: lnb, line: line)
|
17
17
|
[:exa, node]
|
18
18
|
when State.include_match(line)
|
19
19
|
node = node.add_include(lnb: lnb)
|
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.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2020-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|