buzz_logic 1.0.0 → 1.0.2
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +18 -5
- data/lib/buzz_logic/engine.rb +10 -12
- data/lib/buzz_logic/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a998ef0a6a784ee9eca2d8883000f8850822925cad087ccf920bcd92ae4361f
|
4
|
+
data.tar.gz: d44764e06bd79f955b6244bbc64245b02c2d186151975eee6138725260b32e9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c169e21f1b1ec8d7def2b3f3304b6b0c3ef3323551a8c4ea676bd0286d0a43623395c97b070e5cae8dbea3726272ed9e9e5625d74e6e6f4208c46e728478a9
|
7
|
+
data.tar.gz: bc8864a7bbedb646757e4910262b208ccf60494ef07cba62724b1d8e21f22f57c35b6a08ae5e5b8b6d14061c696703b36be40b490210edfa82309f2b63326fa2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Buzz Logic - Change Log
|
2
2
|
|
3
|
+
## [1.0.2] - 2025-06-17
|
4
|
+
|
5
|
+
- Limit the models methods to the attributes returned from the `attributes` method
|
6
|
+
-
|
7
|
+
## [1.0.1] - 2025-06-16
|
8
|
+
|
9
|
+
- Fix: Ignore method arity
|
10
|
+
|
3
11
|
## [1.0.0] - 2025-06-16
|
4
12
|
|
5
13
|
- First version of BuzzLogic, extracted from FutureFund.
|
data/README.md
CHANGED
@@ -44,16 +44,25 @@ The primary interface for the engine is the BuzzLogic::RulesEngine.evaluate meth
|
|
44
44
|
### Basic Example
|
45
45
|
|
46
46
|
```ruby
|
47
|
-
require
|
47
|
+
require "buzz_logic"
|
48
48
|
|
49
49
|
# Define some objects to evaluate against
|
50
|
-
|
51
|
-
|
50
|
+
Student = Struct.new(:grade, :has_permission_slip) do
|
51
|
+
def attributes
|
52
|
+
to_h.map { |k, v| [ k.to_s, v ] }.to_h
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Fundraiser = Struct.new(:status, :goal_amount) do
|
57
|
+
def attributes
|
58
|
+
to_h.transform_keys(&:to_s)
|
59
|
+
end
|
60
|
+
end
|
52
61
|
|
53
62
|
# The context maps the names used in the rule to the objects
|
54
63
|
context = {
|
55
|
-
|
56
|
-
|
64
|
+
"student" => Student.new(grade: 5, has_permission_slip: true),
|
65
|
+
"fundraiser" => Fundraiser.new(status: 'active', goal_amount: 500)
|
57
66
|
}
|
58
67
|
|
59
68
|
# Define a rule
|
@@ -86,6 +95,10 @@ puts "Is the student eligible? #{result}" # => true
|
|
86
95
|
|
87
96
|
Parentheses `()` can be used to group expressions and control precedence.
|
88
97
|
|
98
|
+
## Attributes
|
99
|
+
|
100
|
+
The object must respond to the `attributes` method and return a hash with string keys (not symbols).
|
101
|
+
|
89
102
|
### Security
|
90
103
|
|
91
104
|
Security is the queen bee of BuzzLogic's design. Unlike approaches that use eval, BuzzLogic parses the rule into an Abstract Syntax Tree (AST) and then interprets it.
|
data/lib/buzz_logic/engine.rb
CHANGED
@@ -145,20 +145,18 @@ module BuzzLogic
|
|
145
145
|
def resolve_attribute(object, attribute)
|
146
146
|
raise EvaluationError, "Cannot access attribute on nil" if object.nil?
|
147
147
|
|
148
|
-
|
149
|
-
|
150
|
-
if method.arity == 0
|
151
|
-
return method.call
|
152
|
-
else
|
153
|
-
raise EvaluationError, "Access to method '#{attribute}' with arguments is not allowed."
|
154
|
-
end
|
148
|
+
unless object.respond_to?(:attributes)
|
149
|
+
raise EvaluationError, "Object of type #{object.class} does not have an attributes method"
|
155
150
|
end
|
156
151
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
152
|
+
attrs = object.attributes
|
153
|
+
attr_name = attribute.to_s
|
154
|
+
|
155
|
+
if attrs.key?(attr_name)
|
156
|
+
attrs[attr_name]
|
157
|
+
else
|
158
|
+
raise EvaluationError, "Object of type #{object.class} does not have attribute '#{attr_name}'"
|
159
|
+
end
|
162
160
|
end
|
163
161
|
|
164
162
|
def perform_operation(op, left, right)
|
data/lib/buzz_logic/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buzz_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darian Shimy
|
@@ -32,6 +32,7 @@ licenses:
|
|
32
32
|
- MIT
|
33
33
|
metadata:
|
34
34
|
allowed_push_host: https://rubygems.org
|
35
|
+
rubygems_mfa_required: 'true'
|
35
36
|
homepage_uri: https://github.com/futurefund/buzz_logic
|
36
37
|
source_code_uri: https://github.com/futurefund/buzz_logic
|
37
38
|
changelog_uri: https://github.com/FutureFund/buzz_logic/CHANGELOG.md
|