Skip to content

Commit 94654c4

Browse files
committed
rename and shit
1 parent dae6b70 commit 94654c4

21 files changed

+116
-110
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## [Unreleased]
22

3-
## [0.1.0] - 2024-03-XX
3+
## [0.1.0] - 2024-03-27
44
- Initial release

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source "https://rubygems.org"
44

5-
# Specify your gem's dependencies in expressive.gemspec
5+
# Specify your gem's dependencies in portable_expressions.gemspec
66
gemspec
77

88
gem "rake", "~> 13.0"

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
expressive (0.1.0)
4+
portable_expressions (0.1.0)
55

66
GEM
77
remote: https://rubygems.org/
@@ -40,7 +40,7 @@ PLATFORMS
4040
ruby
4141

4242
DEPENDENCIES
43-
expressive!
43+
portable_expressions!
4444
minitest (~> 5.16)
4545
rake (~> 13.0)
4646
rubocop (~> 1.21)

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# Expressive 🧠
1+
# PortableExpressions 🍱
22

3-
A simple and flexible pure Ruby library for building and evaluating expressions.
3+
A simple and flexible pure Ruby library for building and evaluating expressions. Expressions can be serialized to and built from JSON strings for portability.
44

55
## Installation
66

77
Install the gem and add to the application's Gemfile by executing:
88

9-
`bundle add expressive`
9+
`bundle add portable_expressions`
1010

1111
If bundler is not being used to manage dependencies, install the gem by executing:
1212

13-
`gem install expressive`
13+
`gem install portable_expressions`
1414

1515
## Usage
1616

1717
> [!IMPORTANT]
18-
> When using the gem, all references to the models below must be prefixed with `Expressive::`. This is omitted in the README for simplicity.
18+
> When using the gem, all references to the models below must be prefixed with `PortableExpressions::`. This is omitted in the README for simplicity.
1919
2020
### Scalar
2121

@@ -43,9 +43,15 @@ environment.evaluate(variable_b) #=> MissingVariableError
4343

4444
### Expression
4545

46-
An expression represents 2 or more `operands` that are reduced using a defined `operator`. The `operands` of an `Expression` can be `Scalars`, `Variables`, or other `Expressions`. All `operands` must respond to the symbol (i.e. support the method) defined by the `Expression#operator`.
46+
An expression represents 2 or more `operands` that are reduced using a defined `operator`. The `operands` of an `Expression` can be `Scalars`, `Variables`, or other `Expressions`. All `operands` must respond to the symbol (i.e. support the method) defined by the `Expression#operator`. Just like `Variables`, `Expressions` have non value until they're evaluated by an `Environment`.
4747

48-
And `Expression` can store its result back into the `Environment` by defining an `output`.
48+
Evaluating an `Expression` does the following:
49+
1. all `operands` are first evaluated in order
50+
1. all resulting _values_ are reduced using the symbol defined by the `operator`
51+
52+
In this way evaluation is "lazy"; it won't evaluate a `Variable` or `Expression` until the `operand` is about to be used.
53+
54+
An `Expression` can store its result back into the `Environment` by defining an `output`.
4955

5056
```ruby
5157
# addition
@@ -70,7 +76,7 @@ environment.variables
7076

7177
#### Special `operators`
7278

73-
Some operators, like logical `&&` and `||` are not methods in Ruby, so we pass a special string/symbol that Expressive understands.
79+
Some operators, like logical `&&` and `||` are not methods in Ruby, so we pass a special string/symbol that PortableExpressions understands.
7480
- `&&` is represented by `:and`
7581
- `||` is represented by `:or`
7682

@@ -136,26 +142,26 @@ All models have a **required** `object` key that indicates the type of object.
136142

137143
### Building (from JSON)
138144

139-
To parse a JSON string, use the `Expressive.from_json` method.
145+
To parse a JSON string, use the `PortableExpressions.from_json` method.
140146

141147
```ruby
142148
environment_json = <<~JSON
143149
{
144-
"object": "Expressive::Environment",
150+
"object": "PortableExpressions::Environment",
145151
"variables": {
146152
"score_a": 100
147153
}
148154
}
149155
JSON
150156
variable_json = <<~JSON
151157
{
152-
"object": "Expressive::Variable",
158+
"object": "PortableExpressions::Variable",
153159
"name": "score_a"
154160
}
155161
JSON
156162

157-
environment = Expressive.from_json(environment_json)
158-
variable_score_a = Expressive.from_json(variable_json)
163+
environment = PortableExpressions.from_json(environment_json)
164+
variable_score_a = PortableExpressions.from_json(variable_json)
159165
environment.evaluate(variable_score_a) #=> 100
160166
```
161167

@@ -207,7 +213,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
207213

208214
## Contributing
209215

210-
Bug reports and pull requests are welcome on GitHub at https://github.com/omkarmoghe/expressive.
216+
Bug reports and pull requests are welcome on GitHub at https://github.com/omkarmoghe/portable_expressions.
211217

212218
## License
213219

bin/console

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
require "bundler/setup"
5-
require "expressive"
5+
require "portable_expressions"
66

77
# You can add fixtures and/or initialization code here to make experimenting
88
# with your gem easier. You can also use a different console, if you like.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
require "delegate"
55
require "json"
66

7-
require_relative "expressive/version"
8-
require_relative "expressive/modules/serializable"
9-
require_relative "expressive/evaluator"
10-
require_relative "expressive/scalar"
11-
require_relative "expressive/variable"
12-
require_relative "expressive/expression"
13-
require_relative "expressive/environment"
7+
require_relative "portable_expressions/version"
8+
require_relative "portable_expressions/modules/serializable"
9+
require_relative "portable_expressions/evaluator"
10+
require_relative "portable_expressions/scalar"
11+
require_relative "portable_expressions/variable"
12+
require_relative "portable_expressions/expression"
13+
require_relative "portable_expressions/environment"
1414

15-
module Expressive
15+
module PortableExpressions
1616
Error = Class.new(StandardError)
1717

1818
DeserializationError = Class.new(Error)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module Expressive
3+
module PortableExpressions
44
# The `Environment` holds state in the form of a `variables` hash and can evaluate `Expressions`, `Scalars`, and
55
# `Variables` within a context.
66
class Environment
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module Expressive
3+
module PortableExpressions
44
# Used to wrap `operands` when evaluating an `Expression`. This allows us to "extend" the functionality of an object
55
# without polluting the app wide definition.
66
class Evaluator < SimpleDelegator
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module Expressive
3+
module PortableExpressions
44
# An expression represents 2 or more `operands` that are reduced using a defined `operator`. The `operands` of an
55
# `Expression` can be `Scalars`, `Variables`, or other `Expressions`. All `operands` must respond to the symbol (i.e.
66
# support the method) defined by the `Expression#operator`.

lib/expressive/modules/serializable.rb renamed to lib/portable_expressions/modules/serializable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module Expressive
3+
module PortableExpressions
44
module Serializable
55
def as_json
66
{

0 commit comments

Comments
 (0)