appenv 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/appenv/environment.rb +62 -5
- data/lib/appenv/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aef3777b394fe61bdbb200d3cbd929ca376545f5cbbf00974addc76fce4837ea
|
4
|
+
data.tar.gz: 2cc83fdca529d448a6082d908453fb636b0b4a5e0f8c5159a17e5cce3d571932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e934242f875a5cd60263420648df862f6bf372e35300193869ce6a1c47e0ffa88bc9ea1408a9aa72799a636d4338e5636d2cf8569f7e5fad1334fa499cef278
|
7
|
+
data.tar.gz: eb853acb47eadc57301dd987692a534da7ba1fcd4d2e67942decbc442a283dab947e6595174a9bd979c4b0064dcc0476e9ac04a3669160de0c68dd5f8f129bf2
|
data/lib/appenv/environment.rb
CHANGED
@@ -21,8 +21,8 @@ class AppEnv::Environment < ActiveSupport::OrderedOptions
|
|
21
21
|
# }
|
22
22
|
#
|
23
23
|
def expand(&blk)
|
24
|
-
source = _compile_source_env
|
25
|
-
blk.call(self, source)
|
24
|
+
@source = _compile_source_env
|
25
|
+
blk.call(self, @source)
|
26
26
|
end
|
27
27
|
|
28
28
|
|
@@ -32,7 +32,7 @@ class AppEnv::Environment < ActiveSupport::OrderedOptions
|
|
32
32
|
# # Simple variable assignment:
|
33
33
|
# env.var1 = src.var_one
|
34
34
|
#
|
35
|
-
# # Variable assignment with
|
35
|
+
# # Variable assignment with a block:
|
36
36
|
# env.set(:var2) {
|
37
37
|
# if abcd?
|
38
38
|
# 'xyz'
|
@@ -41,8 +41,65 @@ class AppEnv::Environment < ActiveSupport::OrderedOptions
|
|
41
41
|
# end
|
42
42
|
# }
|
43
43
|
#
|
44
|
-
def set(property,
|
45
|
-
self
|
44
|
+
def set(property, value = nil)
|
45
|
+
self[property] = block_given? ? yield : value
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
# Creates a property in the env, taking the value from the source hash.
|
50
|
+
# If you want to modify the value from the source before setting it in
|
51
|
+
# the env, supply a block that takes the src value and returns the env value.
|
52
|
+
#
|
53
|
+
# Options:
|
54
|
+
# * :from -- if the source property name differs, supply it
|
55
|
+
# * :required -- raise an error if the property is not assigned a value
|
56
|
+
#
|
57
|
+
def apply(property, options = {})
|
58
|
+
if options.kind_of?(String) || options.kind_of?(Symbol)
|
59
|
+
options = { :from => options }
|
60
|
+
end
|
61
|
+
val = @source[options[:from] || property]
|
62
|
+
self[property] = block_given? ? yield(val) : val
|
63
|
+
assert(property) if options[:required]
|
64
|
+
self[property]
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# Collect all the source properties that match the pattern as a hash.
|
69
|
+
# If a block is given, yield the hash to the block, which can modify values.
|
70
|
+
# Then merge the hash into the env.
|
71
|
+
#
|
72
|
+
def splat(pattern)
|
73
|
+
hash = ActiveSupport::OrderedOptions.new
|
74
|
+
@source.each_pair { |k, v| hash[k] ||= v if k.to_s.match(pattern) }
|
75
|
+
yield(hash) if block_given?
|
76
|
+
self.update(hash)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# After setting all the environment properties, assert which
|
81
|
+
# properties should exist. The Configurator will raise an
|
82
|
+
# exception listing the missing properties, if any.
|
83
|
+
#
|
84
|
+
def assert(*properties)
|
85
|
+
missing = properties.collect { |prop|
|
86
|
+
prop.to_s.upcase unless self[prop]
|
87
|
+
}.compact
|
88
|
+
raise("AppEnv requires #{missing.join(', ')}") if missing.any?
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# Collect a line-by-line list of strings in the form: 'property = value'.
|
93
|
+
#
|
94
|
+
def to_a
|
95
|
+
collect { |k, v| "#{k} = #{v.inspect}" }
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
# Print a line-by-line list of env values to STDOUT.
|
100
|
+
#
|
101
|
+
def print(pad = '')
|
102
|
+
puts pad+to_a.join("\n"+pad)
|
46
103
|
end
|
47
104
|
|
48
105
|
|
data/lib/appenv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Pearson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -36,7 +36,8 @@ files:
|
|
36
36
|
homepage: https://github.com/joseph/appenv
|
37
37
|
licenses:
|
38
38
|
- MIT
|
39
|
-
metadata:
|
39
|
+
metadata:
|
40
|
+
github_repo: ssh://github.com/bksh/appenv
|
40
41
|
post_install_message:
|
41
42
|
rdoc_options: []
|
42
43
|
require_paths:
|
@@ -52,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
53
|
- !ruby/object:Gem::Version
|
53
54
|
version: '0'
|
54
55
|
requirements: []
|
55
|
-
rubygems_version: 3.0.
|
56
|
+
rubygems_version: 3.0.3.1
|
56
57
|
signing_key:
|
57
58
|
specification_version: 4
|
58
59
|
summary: Application environment configuration
|