inquisitive 1.1.0 → 1.2.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0386fe6dcde04e8963c090b8b2e937003cd0f23a
|
4
|
+
data.tar.gz: fd157641b836c285be3f496e644d25eedd2dc8ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bdaac4757a5166432c9a0af4b31d78d33d07498a7ce6ee2b2d5b9daedb0a58c581a6f7e6edcf5fd906c955030f13fe34dc81d05fd3ecef953e3dc7961a0cef0
|
7
|
+
data.tar.gz: 429c3aed3a0de7a9c99ef3ebce6d381baab13c9b577d7678954000a40e6b3b264e0ffdf4142c818a312d68a11cd2a3292695d247c7ab4ebb260c77983011c201
|
data/README.md
CHANGED
@@ -139,7 +139,7 @@ ENV['STUB_IN'] = "development"
|
|
139
139
|
ENV['STUB_SERVICES'] = "database,api"
|
140
140
|
class MyGame
|
141
141
|
extend Inquisitive::Environment
|
142
|
-
inquires_about '
|
142
|
+
inquires_about 'STUB_'
|
143
143
|
end
|
144
144
|
|
145
145
|
MyGame.stub.authentication?
|
@@ -183,7 +183,7 @@ Environment inquirers can have explicit presence checks, circumventing a common
|
|
183
183
|
ENV['STUB_AUTHENTICATION'] = 'false'
|
184
184
|
class MyGame
|
185
185
|
extend Inquisitive::Environment
|
186
|
-
inquires_about '
|
186
|
+
inquires_about 'STUB_'
|
187
187
|
end
|
188
188
|
|
189
189
|
MyGame.stub.authentication
|
@@ -229,7 +229,7 @@ Environment inquirers have three configurable modes, defaulting to `:dynamic`:
|
|
229
229
|
```ruby
|
230
230
|
class MyGame
|
231
231
|
extend Inquisitive::Environment
|
232
|
-
inquires_about '
|
232
|
+
inquires_about 'STUB_', mode: %i[dynamic cached static].sample
|
233
233
|
end
|
234
234
|
```
|
235
235
|
|
data/inquisitive.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "inquisitive"
|
7
|
-
spec.version = "1.
|
7
|
+
spec.version = "1.2.0"
|
8
8
|
spec.authors = ["Chris Keele"]
|
9
9
|
spec.email = ["dev@chriskeele.com"]
|
10
10
|
spec.description = "Predicate methods for those curious about their datastructures."
|
@@ -4,7 +4,7 @@ module Inquisitive
|
|
4
4
|
|
5
5
|
def inquires_about(env_var, opts={})
|
6
6
|
|
7
|
-
env_accessor = opts.fetch(:with, env_var.downcase)
|
7
|
+
env_accessor = opts.fetch(:with, env_var.downcase[/(.*?)(?=(?:_$|$))/])
|
8
8
|
@__env_accessors__ ||= HashWithIndifferentAccess.new
|
9
9
|
@__env_accessors__[env_accessor] = env_var
|
10
10
|
|
@@ -58,24 +58,30 @@ module Inquisitive
|
|
58
58
|
env_var
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
elsif hash_var? var_name
|
62
62
|
|
63
63
|
Parser.env_keys_from(var_name).reduce({}) do |hash, key|
|
64
64
|
hash[Parser.key_for(key, var_name)] = Inquisitive[Parser[key]]
|
65
65
|
hash
|
66
66
|
end
|
67
67
|
|
68
|
+
else
|
69
|
+
""
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
73
|
+
def hash_var?(var_name)
|
74
|
+
var_name[-1] == '_'
|
75
|
+
end
|
76
|
+
|
71
77
|
def env_keys_from(var_name)
|
72
78
|
ENV.keys.select do |key|
|
73
|
-
key =~ /^#{var_name}
|
79
|
+
key =~ /^#{var_name}/
|
74
80
|
end
|
75
81
|
end
|
76
82
|
|
77
83
|
def key_for(env_key, var_name)
|
78
|
-
env_key.gsub("#{var_name}
|
84
|
+
env_key.gsub("#{var_name}", '').downcase
|
79
85
|
end
|
80
86
|
|
81
87
|
end
|
@@ -3,11 +3,20 @@ require 'test_helper'
|
|
3
3
|
class InquisitiveEnvironmentTest < EnvironmentTest
|
4
4
|
|
5
5
|
def test_missing_variable_responses
|
6
|
-
App.inquires_about '
|
7
|
-
assert_equal App.exists,
|
6
|
+
App.inquires_about 'DOES_NOT_EXIST', with: :exists
|
7
|
+
assert_equal App.exists, ""
|
8
8
|
end
|
9
9
|
def test_missing_variable_predicates
|
10
|
-
App.inquires_about '
|
10
|
+
App.inquires_about 'DOES_NOT_EXIST', with: :exists
|
11
|
+
refute App.exists?
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_missing_hash_variable_responses
|
15
|
+
App.inquires_about 'DOES_NOT_EXIST_', with: :exists
|
16
|
+
assert_equal App.exists, {}
|
17
|
+
end
|
18
|
+
def test_missing_hash_variable_predicates
|
19
|
+
App.inquires_about 'DOES_NOT_EXIST_', with: :exists
|
11
20
|
refute App.exists?
|
12
21
|
end
|
13
22
|
|
@@ -15,7 +15,7 @@ module CombinatorialEnvironmentTests
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_changing_variable_after_definition
|
18
|
-
App.inquires_about @type.upcase, mode: @mode, with: :precache
|
18
|
+
App.inquires_about @type.upcase + (@type == "hash" ? "_" : ""), mode: @mode, with: :precache
|
19
19
|
test = @mode.static? ? :assert_equal : :refute_equal
|
20
20
|
precache = App.precache
|
21
21
|
send :"change_#{@type}_variable"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inquisitive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Keele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|