travis-ci
1706 of 1706 new or added lines in 47 files covered. (100.0%)
1629 of 1708 relevant lines covered (95.37%)
479.7 hits per line
|
require 'gem/release/helper/hash'
|
2✔ |
2 |
|
|
|
module Gem |
2✔ |
|
module Release |
2✔ |
|
class Config |
2✔ |
|
class Env |
2✔ |
|
include Helper::Hash |
2✔ |
8 |
|
|
|
PREFIX = 'GEM_RELEASE_' |
2✔ |
|
TRUE = /^(true|yes|on)$/ |
2✔ |
|
FALSE = /^(false|no|off)$/ |
2✔ |
12 |
|
|
|
def load |
2✔ |
|
opts = vars.map { |key, value| to_hash(keys_for(key), cast(value)) } |
1,102✔ |
|
opts = opts.inject { |one, other| deep_merge(one, other) } |
1,098✔ |
|
opts || {} |
1,090✔ |
17 |
end
|
|
18 |
|
|
|
private |
2✔ |
20 |
|
|
|
def vars |
2✔ |
|
ENV.select { |key, _| key.start_with?(PREFIX) } |
119,912✔ |
23 |
end
|
|
24 |
|
|
|
def keys_for(key) |
2✔ |
|
key.sub(PREFIX, '').split('_').map(&:downcase).map(&:to_sym) |
12✔ |
27 |
end
|
|
28 |
|
|
|
def to_hash(keys, value) |
2✔ |
|
keys = keys.reverse |
12✔ |
|
keys.inject(keys.shift => value) { |value, key| { key => value } } |
22✔ |
32 |
end
|
|
33 |
|
|
|
def cast(value) |
2✔ |
|
case value
|
12✔ |
36 |
when TRUE |
|
|
true
|
4✔ |
38 |
when FALSE |
|
|
false
|
6✔ |
40 |
when '' |
|
|
false
|
× |
42 |
else
|
|
|
value |
2✔ |
44 |
end
|
|
45 |
end
|
|
46 |
end
|
|
47 |
end
|
|
48 |
end
|
|
49 |
end
|