config-reader 0.0.2 → 0.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/config-reader.rb +24 -7
- data/lib/config-reader/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c7acec20176a0287255bd5bfef69fa7445d19d63f5073ee926fe7c6fb60e9e2
|
4
|
+
data.tar.gz: 873c7606ef11f1b8e8f63bf37a80a443f129145c2cdde6ab6c5bb6e2f95b22b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc52814e3832ce11f01512f56f3dc315757af119159491960df868d394018f39e044a3b19460d6fd5097e223a565d92c178bd909e3eca1eb488edabe4e550330
|
7
|
+
data.tar.gz: 3d73af20dd3f8abeb910ef99a83d2555260768c0903c9e9d9cc0b6f1bfa6222a5de4d9e56b3c027aab2b2ef08265ae9ba7293c4656c8337899e451c9d3ffb626
|
data/lib/config-reader.rb
CHANGED
@@ -3,13 +3,30 @@ require 'erb'
|
|
3
3
|
require 'ostruct'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
+
# Process the input as ERB and then YAML and return results as OpenStruct
|
6
7
|
class ConfigReader
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
attr_reader :file_path, :environment
|
9
|
+
|
10
|
+
def initialize(file_path, environment)
|
11
|
+
@file_path = file_path
|
12
|
+
@environment = environment.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def config
|
16
|
+
@config ||= OpenStruct.new(yaml)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def yaml
|
22
|
+
YAML.load(erb)[environment]
|
23
|
+
end
|
24
|
+
|
25
|
+
def erb
|
26
|
+
ERB.new(input).result
|
27
|
+
end
|
28
|
+
|
29
|
+
def input
|
30
|
+
IO.read(file_path)
|
14
31
|
end
|
15
32
|
end
|