nocode 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/lib/nocode/util/object_template.rb +1 -3
- data/lib/nocode/version.rb +1 -1
- data/lib/nocode.rb +1 -0
- data/nocode.gemspec +2 -0
- metadata +22 -3
- data/lib/nocode/util/string_template.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f199fcae3341fccc2e54c1c139ba2c7e65a20dda27d2be31c79de02f9ec2558a
|
4
|
+
data.tar.gz: c10d64f895d34e567b846c52727205d1394641adcd68b1b1d2707c509577700c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a53bcec0412b9b8be57d9cb61601db583aa210542f9372c05d4cdee0e693861d05e017a697103253a2d522a2253e609481ded8e0524362ccaf6640a9d13f9d3
|
7
|
+
data.tar.gz: 131855e439116d1718cf46c53cc32597187aeae36156d71fff508fa4a0a20739a9965b055874aadc93cae4a5dd3fbf3f4b0201d5f7c75a9d1d63ed60e9150044
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'string_template'
|
4
|
-
|
5
3
|
module Nocode
|
6
4
|
module Util
|
7
5
|
# Built on top of StringTemplate but instead of only working for a string, this will
|
@@ -34,7 +32,7 @@ module Nocode
|
|
34
32
|
[recursive_evaluate(k, values), recursive_evaluate(v, values)]
|
35
33
|
end
|
36
34
|
when String
|
37
|
-
|
35
|
+
Nay.evaluate(expression, values)
|
38
36
|
else
|
39
37
|
expression
|
40
38
|
end
|
data/lib/nocode/version.rb
CHANGED
data/lib/nocode.rb
CHANGED
data/nocode.gemspec
CHANGED
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nocode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nay
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.0.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.0.2
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: bundler-audit
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -209,7 +229,6 @@ files:
|
|
209
229
|
- lib/nocode/util/dictionary.rb
|
210
230
|
- lib/nocode/util/object_template.rb
|
211
231
|
- lib/nocode/util/optionable.rb
|
212
|
-
- lib/nocode/util/string_template.rb
|
213
232
|
- lib/nocode/version.rb
|
214
233
|
- nocode.gemspec
|
215
234
|
homepage: https://github.com/mattruggio/nocode
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nocode
|
4
|
-
module Util
|
5
|
-
# Takes in an expression and interpolates in any parameters using << >> notation.
|
6
|
-
# For example:
|
7
|
-
# input = { 'person' => 'hops' }
|
8
|
-
# Nocode::Util::StringTemplate.new("Hello, << person.name >>!").evaluate(input)
|
9
|
-
# Should produce: "Hello, hops!"
|
10
|
-
class StringTemplate
|
11
|
-
LEFT_TOKEN = '<<'
|
12
|
-
RIGHT_TOKEN = '>>'
|
13
|
-
SEPARATOR = '.'
|
14
|
-
REG_EXPR = /#{Regexp.quote(LEFT_TOKEN)}(.*?)#{Regexp.quote(RIGHT_TOKEN)}/.freeze
|
15
|
-
|
16
|
-
attr_reader :expression
|
17
|
-
|
18
|
-
def initialize(expression)
|
19
|
-
@expression = expression.to_s
|
20
|
-
|
21
|
-
freeze
|
22
|
-
end
|
23
|
-
|
24
|
-
def evaluate(values = {})
|
25
|
-
resolved = tokens_to_values(tokens, values)
|
26
|
-
|
27
|
-
tokens.inject(expression) do |memo, token|
|
28
|
-
memo.gsub("#{LEFT_TOKEN}#{token}#{RIGHT_TOKEN}", resolved[token].to_s)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def tokens
|
35
|
-
expression.to_s.scan(REG_EXPR).flatten
|
36
|
-
end
|
37
|
-
|
38
|
-
def tokens_to_values(tokens, values)
|
39
|
-
tokens.each_with_object({}) do |token, memo|
|
40
|
-
cleansed = token.strip
|
41
|
-
parts = cleansed.split(SEPARATOR)
|
42
|
-
value = values.dig(*parts)
|
43
|
-
|
44
|
-
memo[token] = value
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|