factbase 0.5.1 → 0.5.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: c672da652030c0c4a1405ce4d84b91e0ca776d342d1418be9b01d18ea6d70703
4
- data.tar.gz: '068e446b24c80857c7c26724b22bd58d8644f8fa6db76223eb786d00fb422e1a'
3
+ metadata.gz: f4cc974ce82891e109f03740f7562f798e955da874dc2b1a91b0858bda7206b0
4
+ data.tar.gz: 7aac5d75a5e10fca5a6f74e9fc2e5b83ecaf9cc9d669e3384c52b508b732b45f
5
5
  SHA512:
6
- metadata.gz: f3cc8aae4d769dc4103a5501d4ff8e3093dbbdb0084b3f705d0b8d4dc70667f7828ae7bc39585e68c45891c94a926828e899110e34f3a76aad918e8acf9f319c
7
- data.tar.gz: 062e0dc1dd5f90e5d9555baa2f2d79f957180d2a1c823a35bb296db43708d9feacb9f9b1465c0bfc411245aeba981dee0a902d22c806febf99f6676911354a7d
6
+ metadata.gz: 436eb0bc06eabc25825b36fdf8293f2654219e42a0470512d42bc075670a25d51936006303a67a4c183b7208ef1a9c8a940ab227af838fc4b4f8ae8020be4c4e
7
+ data.tar.gz: e7ea774220cdef5e471cb66c666c3cea20ee0672991b1e0fa5797b60f31e5430c9a0e9b4a40298d68654d067b1c1c1c8318fff492ba0162217cdb9724af8133e
data/Gemfile.lock CHANGED
@@ -14,24 +14,23 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- actionpack (7.2.2.1)
18
- actionview (= 7.2.2.1)
19
- activesupport (= 7.2.2.1)
17
+ actionpack (8.0.1)
18
+ actionview (= 8.0.1)
19
+ activesupport (= 8.0.1)
20
20
  nokogiri (>= 1.8.5)
21
- racc
22
- rack (>= 2.2.4, < 3.2)
21
+ rack (>= 2.2.4)
23
22
  rack-session (>= 1.0.1)
24
23
  rack-test (>= 0.6.3)
25
24
  rails-dom-testing (~> 2.2)
26
25
  rails-html-sanitizer (~> 1.6)
27
26
  useragent (~> 0.16)
28
- actionview (7.2.2.1)
29
- activesupport (= 7.2.2.1)
27
+ actionview (8.0.1)
28
+ activesupport (= 8.0.1)
30
29
  builder (~> 3.1)
31
30
  erubi (~> 1.11)
32
31
  rails-dom-testing (~> 2.2)
33
32
  rails-html-sanitizer (~> 1.6)
34
- activesupport (7.2.2.1)
33
+ activesupport (8.0.1)
35
34
  base64
36
35
  benchmark (>= 0.3)
37
36
  bigdecimal
@@ -43,6 +42,7 @@ GEM
43
42
  minitest (>= 5.1)
44
43
  securerandom (>= 0.3)
45
44
  tzinfo (~> 2.0, >= 2.0.5)
45
+ uri (>= 0.13.1)
46
46
  ansi (1.5.0)
47
47
  ast (2.4.2)
48
48
  backtrace (0.4.0)
@@ -114,9 +114,9 @@ GEM
114
114
  rails-html-sanitizer (1.6.2)
115
115
  loofah (~> 2.21)
116
116
  nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
117
- railties (7.2.2.1)
118
- actionpack (= 7.2.2.1)
119
- activesupport (= 7.2.2.1)
117
+ railties (8.0.1)
118
+ actionpack (= 8.0.1)
119
+ activesupport (= 8.0.1)
120
120
  irb (~> 1.13)
121
121
  rackup (>= 1.0.0)
122
122
  rake (>= 12.2)
@@ -157,7 +157,7 @@ GEM
157
157
  rubocop-ast (>= 1.36.2, < 2.0)
158
158
  ruby-progressbar (~> 1.7)
159
159
  unicode-display_width (>= 2.4.0, < 4.0)
160
- rubocop-ast (1.37.0)
160
+ rubocop-ast (1.38.0)
161
161
  parser (>= 3.3.1.0)
162
162
  rubocop-minitest (0.36.0)
163
163
  rubocop (>= 1.61, < 2.0)
@@ -189,10 +189,11 @@ GEM
189
189
  unicode-display_width (3.1.4)
190
190
  unicode-emoji (~> 4.0, >= 4.0.4)
191
191
  unicode-emoji (4.0.4)
192
+ uri (1.0.2)
192
193
  useragent (0.16.11)
193
194
  yaml (0.4.0)
194
195
  yard (0.9.37)
195
- zeitwerk (2.6.18)
196
+ zeitwerk (2.7.1)
196
197
 
197
198
  PLATFORMS
198
199
  arm64-darwin-22
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'backtrace'
23
24
  require 'time'
24
25
  require_relative '../factbase'
25
26
  require_relative 'fact'
@@ -56,6 +57,8 @@ class Factbase::Syntax
56
57
  def initialize(fb, query, term: Factbase::Term)
57
58
  @fb = fb
58
59
  @query = query
60
+ raise "Term must be a Class, while #{term.class.name} provided" unless term.is_a?(Class)
61
+ raise "The 'term' must be a child of Factbase::Term, while #{term.name} provided" unless term <= Factbase::Term
59
62
  @term = term
60
63
  end
61
64
 
@@ -69,7 +72,7 @@ class Factbase::Syntax
69
72
  t
70
73
  end
71
74
  rescue StandardError => e
72
- err = "#{e.message} (#{e.backtrace.take(5).join('; ')}) in \"#{@query}\""
75
+ err = "#{e.message} (#{Backtrace.new(e)}) in \"#{@query}\""
73
76
  err = "#{err}, tokens: #{@tokens}" unless @tokens.nil?
74
77
  raise err
75
78
  end
@@ -83,10 +86,10 @@ class Factbase::Syntax
83
86
  raise 'No tokens' if @tokens.empty?
84
87
  @ast ||= to_ast(@tokens, 0)
85
88
  raise "Too many terms (#{@ast[1]} != #{@tokens.size})" if @ast[1] != @tokens.size
86
- term = @ast[0]
87
- raise 'No terms found' if term.nil?
88
- raise "Not a term: #{@term.class.name.inspect}" unless term.is_a?(@term)
89
- term
89
+ t = @ast[0]
90
+ raise 'No terms found in the AST' if t.nil?
91
+ raise "#{t.class.name} is not an instance of #{@term}, thus not a proper term" unless t.is_a?(@term)
92
+ t
90
93
  end
91
94
 
92
95
  # Reads the stream of tokens, starting at the +at+ position. If the
@@ -114,7 +117,9 @@ class Factbase::Syntax
114
117
  operands << operand
115
118
  break if tokens[at] == :close
116
119
  end
117
- [Factbase::TermOnce.new(@term.new(@fb, op, operands), @fb.cache), at + 1]
120
+ t = @term.new(@fb, op, operands)
121
+ t = Factbase::TermOnce.new(t, @fb.cache) if t.instance_of?(Factbase::Term)
122
+ [t, at + 1]
118
123
  end
119
124
 
120
125
  # Turns a query into an array of tokens.
data/lib/factbase.rb CHANGED
@@ -81,7 +81,7 @@ require 'yaml'
81
81
  # License:: MIT
82
82
  class Factbase
83
83
  # Current version of the gem (changed by .rultor.yml on every release)
84
- VERSION = '0.5.1'
84
+ VERSION = '0.5.2'
85
85
 
86
86
  # An exception that may be thrown in a transaction, to roll it back.
87
87
  class Rollback < StandardError; end
@@ -145,4 +145,26 @@ class TestSyntax < Minitest::Test
145
145
  assert_equal(t, Factbase::Syntax.new(Factbase.new, s).to_term.to_s)
146
146
  end
147
147
  end
148
+
149
+ def test_fails_when_term_is_not_a_class
150
+ assert_raises(StandardError) { Factbase::Syntax.new(Factbase.new, '(foo 1)', term: 'hello') }
151
+ end
152
+
153
+ def test_fails_when_term_is_wrong_class
154
+ assert_raises(StandardError) { Factbase::Syntax.new(Factbase.new, '(bar 1)', term: String).to_term }
155
+ end
156
+
157
+ def test_fails_when_term_is_incorrectly_defined_class
158
+ assert_includes(
159
+ assert_raises(StandardError) { Factbase::Syntax.new(Factbase.new, '(bar 1)', term: FakeTerm).to_term }.message,
160
+ 'wrong number of arguments'
161
+ )
162
+ end
163
+
164
+ class FakeTerm < Factbase::Term
165
+ def initialize(invalid)
166
+ super
167
+ @x = invalid
168
+ end
169
+ end
148
170
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko