opto 1.5.2 → 1.5.3
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/README.md +39 -0
- data/lib/opto/option.rb +1 -0
- data/lib/opto/resolvers/evaluate.rb +38 -0
- data/lib/opto/resolvers/interpolate.rb +35 -0
- data/lib/opto/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f0ef7542d31a0ad7e239c0cb806b8043fbf180
|
4
|
+
data.tar.gz: 7c8f9cce7e8f4e72ab1e5e5a02e2b7db6ce1e2ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9308afe78c8546a80374aa50001cb6c2db6b16844a0fbf34bc13965da43dce0348a6cec1ba8c383021ae84f4f7e99f7786c692d396c249fd661b4bbb0eeda9e9
|
7
|
+
data.tar.gz: 99d48baecaea59a3d1cffad818fc3799c9d2c36eef1df0a6b311448cca96fc3d409220f3cf687b0d542f732311ce40e878590712faa5f986cd20d8087c03387b
|
data/README.md
CHANGED
@@ -393,6 +393,45 @@ Ignores hint completely.
|
|
393
393
|
|
394
394
|
Output is a 'random' UUID generated by `SecureRandom.uuid`, such as `78b6decf-e312-45a1-ac8c-d562270036ba`
|
395
395
|
|
396
|
+
### evaluate
|
397
|
+
Hint is a calculation. Uses values of other options to perform simple calculations.
|
398
|
+
|
399
|
+
Example:
|
400
|
+
|
401
|
+
```yaml
|
402
|
+
apples:
|
403
|
+
type: integer
|
404
|
+
value: 2
|
405
|
+
|
406
|
+
bananas:
|
407
|
+
type: integer
|
408
|
+
value: 1
|
409
|
+
|
410
|
+
fruits:
|
411
|
+
type: integer
|
412
|
+
from:
|
413
|
+
evaluate: ${apples} + ${bananas}
|
414
|
+
|
415
|
+
# group.value_of('fruits') => 3
|
416
|
+
|
417
|
+
### interpolate
|
418
|
+
Hint is a template. Uses values from other options to build a string.
|
419
|
+
|
420
|
+
Example:
|
421
|
+
|
422
|
+
```yaml
|
423
|
+
place:
|
424
|
+
type: string
|
425
|
+
value: world
|
426
|
+
|
427
|
+
greeting:
|
428
|
+
type: string
|
429
|
+
from:
|
430
|
+
interpolate: Hello, ${place}!
|
431
|
+
|
432
|
+
# group.value_of('greeting') => "Hello, world!"
|
433
|
+
```
|
434
|
+
|
396
435
|
## Default setters
|
397
436
|
|
398
437
|
### env
|
data/lib/opto/option.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'opto/extensions/snake_case'
|
2
|
+
require 'opto/extensions/hash_string_or_symbol_key'
|
3
|
+
|
4
|
+
if RUBY_VERSION < '2.1'
|
5
|
+
using Opto::Extension::SnakeCase
|
6
|
+
using Opto::Extension::HashStringOrSymbolKey
|
7
|
+
end
|
8
|
+
|
9
|
+
module Opto
|
10
|
+
module Resolvers
|
11
|
+
# Geneerate a new random number. Requires :min and :max in hint to define range.
|
12
|
+
class Evaluate < Opto::Resolver
|
13
|
+
|
14
|
+
using Opto::Extension::HashStringOrSymbolKey unless RUBY_VERSION < '2.1'
|
15
|
+
|
16
|
+
def resolve
|
17
|
+
raise TypeError, "String required" unless hint.kind_of?(String)
|
18
|
+
interpolated_hint = hint.gsub(/(?<!\$)\$(?!\$)\{?\w+\}?/) do |v|
|
19
|
+
var = v.tr('${}', '')
|
20
|
+
if option.group.nil? || option.group.option(var).nil?
|
21
|
+
raise RuntimeError, "Variable #{var} not declared"
|
22
|
+
end
|
23
|
+
if option.value_of(var).nil?
|
24
|
+
raise RuntimeError, "No value for #{var}, note that the order is meaningful"
|
25
|
+
end
|
26
|
+
option.value_of(var)
|
27
|
+
end.gsub(/\s+/, "")
|
28
|
+
|
29
|
+
if interpolated_hint =~ /\A[\(\)\-\+\/\*0-9\.]+\z/
|
30
|
+
eval(interpolated_hint)
|
31
|
+
else
|
32
|
+
raise TypeError, "Syntax error: '#{interpolated_hint}' does not look like a number or a calculation"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'opto/extensions/snake_case'
|
2
|
+
require 'opto/extensions/hash_string_or_symbol_key'
|
3
|
+
|
4
|
+
if RUBY_VERSION < '2.1'
|
5
|
+
using Opto::Extension::SnakeCase
|
6
|
+
using Opto::Extension::HashStringOrSymbolKey
|
7
|
+
end
|
8
|
+
|
9
|
+
module Opto
|
10
|
+
module Resolvers
|
11
|
+
# Interpolates values from other options into a template string.
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
# from:
|
15
|
+
# interpolate: mysql://admin:$mysql_admin_pass@mysql:1234/$mysql_db_name
|
16
|
+
class Interpolate < Opto::Resolver
|
17
|
+
|
18
|
+
using Opto::Extension::HashStringOrSymbolKey unless RUBY_VERSION < '2.1'
|
19
|
+
|
20
|
+
def resolve
|
21
|
+
raise TypeError, "String expected" unless hint.kind_of?(String)
|
22
|
+
hint.gsub(/(?<!\$)\$(?!\$)\{?\w+\}?/) do |v|
|
23
|
+
var = v.tr('${}', '')
|
24
|
+
if option.group.nil? || option.group.option(var).nil?
|
25
|
+
raise RuntimeError, "Variable #{var} not declared"
|
26
|
+
end
|
27
|
+
if option.value_of(var).nil?
|
28
|
+
raise RuntimeError, "No value for #{var}, note that the order is meaningful"
|
29
|
+
end
|
30
|
+
option.value_of(var)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/opto/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kimmo Lehto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,7 +74,9 @@ files:
|
|
74
74
|
- lib/opto/resolver.rb
|
75
75
|
- lib/opto/resolvers/default.rb
|
76
76
|
- lib/opto/resolvers/environment_variable.rb
|
77
|
+
- lib/opto/resolvers/evaluate.rb
|
77
78
|
- lib/opto/resolvers/file_content.rb
|
79
|
+
- lib/opto/resolvers/interpolate.rb
|
78
80
|
- lib/opto/resolvers/random_number.rb
|
79
81
|
- lib/opto/resolvers/random_string.rb
|
80
82
|
- lib/opto/resolvers/random_uuid.rb
|