parameter_substitution 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/parameter_substitution.rb +96 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d80f82074e131750e1afb35a41059527cd77ee21
|
4
|
+
data.tar.gz: b1705ba2642c31f7636d6aeb2faaced383783a97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d64da8dee80e1e5e98f3f117e5d5479f851cca7f3fef49963e6c31e3e84de3519bc9ed74d60687439d995f03a2006f3c4522aa35b5a316fa1bbef5a71d18b972
|
7
|
+
data.tar.gz: c7e225edc595863abb9ddf89efff397b5df1288d6b1576d5afd76c6661f42f7131157103f6179960a5108e6d4ce4fec09d4164dbda836f603a16b102626fe285
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# See lib/parameter_substitution/readme.md
|
4
|
+
|
5
|
+
require "parameter_substitution/context"
|
6
|
+
require "parameter_substitution/parse_error"
|
7
|
+
require "parameter_substitution/parser"
|
8
|
+
require "parameter_substitution/transform"
|
9
|
+
require "parameter_substitution/encoder"
|
10
|
+
require "parameter_substitution/method_call_expression"
|
11
|
+
require "parameter_substitution/substitution_expression"
|
12
|
+
require "parameter_substitution/text_expression"
|
13
|
+
require "parameter_substitution/expression"
|
14
|
+
require "parameter_substitution/configuration"
|
15
|
+
require "parameter_substitution/formatters/base"
|
16
|
+
require "parameter_substitution/formatters/date_time_format"
|
17
|
+
Dir[File.dirname(__FILE__) + '/parameter_substitution/formatters/*.rb'].each do |file|
|
18
|
+
require file
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'active_support/all'
|
22
|
+
|
23
|
+
class ParameterSubstitution
|
24
|
+
class SubstitutionError < StandardError; end
|
25
|
+
|
26
|
+
cattr_accessor :config
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def evaluate(
|
30
|
+
input:,
|
31
|
+
mapping:,
|
32
|
+
required_parameters: [],
|
33
|
+
parameter_start: "<",
|
34
|
+
parameter_end: ">",
|
35
|
+
destination_encoding: :text,
|
36
|
+
allow_unknown_replacement_parameters: false,
|
37
|
+
allow_nil: false,
|
38
|
+
allow_unmatched_parameter_end: false
|
39
|
+
)
|
40
|
+
context = ParameterSubstitution::Context.new(
|
41
|
+
input: input,
|
42
|
+
mapping: mapping,
|
43
|
+
required_parameters: required_parameters,
|
44
|
+
parameter_start: parameter_start,
|
45
|
+
parameter_end: parameter_end,
|
46
|
+
destination_encoding: destination_encoding,
|
47
|
+
allow_unknown_replacement_parameters: allow_unknown_replacement_parameters,
|
48
|
+
allow_nil: allow_nil,
|
49
|
+
allow_unmatched_parameter_end: allow_unmatched_parameter_end
|
50
|
+
)
|
51
|
+
|
52
|
+
expression = parse_expression(context)
|
53
|
+
expression.validate
|
54
|
+
[expression.evaluate, expression.warnings]
|
55
|
+
rescue ParameterSubstitution::ParseError => ex
|
56
|
+
[context.input, ex.message]
|
57
|
+
rescue => ex
|
58
|
+
raise SubstitutionError, "Error occurred while parameter substitution: #{ex.message}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def configure
|
62
|
+
config = ParameterSubstitution::Configuration.new
|
63
|
+
yield(config)
|
64
|
+
ParameterSubstitution.config = config
|
65
|
+
end
|
66
|
+
|
67
|
+
def find_tokens(input)
|
68
|
+
context = ParameterSubstitution::Context.new(input: input, mapping: [])
|
69
|
+
parse_expression(context).substitution_parameter_names
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def parse_expression(context)
|
75
|
+
cst = ParameterSubstitution::Parser.new(
|
76
|
+
parameter_start: context.parameter_start,
|
77
|
+
parameter_end: context.parameter_end,
|
78
|
+
allow_unmatched_parameter_end: context.allow_unmatched_parameter_end
|
79
|
+
).parse(context.input)
|
80
|
+
ParameterSubstitution::Transform.new(context).apply(cst)
|
81
|
+
rescue Parslet::ParseFailed => ex
|
82
|
+
if ex.message =~ /Extra input after last repetition at/
|
83
|
+
case context.input[ex.parse_failure_cause.pos.charpos]
|
84
|
+
when context.parameter_start
|
85
|
+
raise ParameterSubstitution::ParseError, "Missing '#{context.parameter_end}' after '#{context.parameter_start}'"
|
86
|
+
when context.parameter_end
|
87
|
+
raise ParameterSubstitution::ParseError, "Missing '#{context.parameter_start}' before '#{context.parameter_end}'"
|
88
|
+
else
|
89
|
+
raise
|
90
|
+
end
|
91
|
+
else
|
92
|
+
raise
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parameter_substitution
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bob Smith
|
8
|
+
- James Ebentier
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-03-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '4.0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '4.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: builder
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bump
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.6.1
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.6.1
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.12'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.12'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: hobo_support
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: invoca-utils
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.0.3
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.0.3
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: parslet
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '1.8'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '1.8'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rake
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '10.0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '10.0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '3.0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '3.0'
|
140
|
+
description: The substitution can be formatted using a syntax that looks like method
|
141
|
+
calls
|
142
|
+
email:
|
143
|
+
- bob@invoca.com
|
144
|
+
- jebentier@invoca.com
|
145
|
+
- cmcgrath@invoca.com
|
146
|
+
executables: []
|
147
|
+
extensions: []
|
148
|
+
extra_rdoc_files: []
|
149
|
+
files:
|
150
|
+
- lib/parameter_substitution.rb
|
151
|
+
homepage: https://github.com/Invoca/parameter_substitution
|
152
|
+
licenses: []
|
153
|
+
metadata: {}
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
requirements: []
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 2.6.13
|
171
|
+
signing_key:
|
172
|
+
specification_version: 4
|
173
|
+
summary: Handles parsing an input strings with embedded substitution parameters and
|
174
|
+
replacing them with values from a provided mapping.
|
175
|
+
test_files: []
|