confg 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45bd8085ff033db9882dce3a0844800ce4f1774e
4
- data.tar.gz: 3b59f41cda4d6f1c783af1f16cb6e55347be3d16
3
+ metadata.gz: 586d879e12ec7af553fbae6344c93d8d3d7651a7
4
+ data.tar.gz: 8a2394ac7e568b0559d6307e73092e6e75a43b39
5
5
  SHA512:
6
- metadata.gz: 47aa0cf019bf18aabb38dc0990e66b5d90c2e26f2b1004d8d1a30c0f261c5b7edfa2b242575df09c438d72e6adc08d855617e3d815fa077ad1c31b32a76b1349
7
- data.tar.gz: 9f06da78306f2b2c65d023a27da90b09a43be63ee6b9f4049ab524523965d8fe21dec25468a267319510884302beb3b79d36f5f1f45c1e70eecc4d40b68a2710
6
+ metadata.gz: caa46a61612f4fa7719381f96843dc8abb96aa8e6a702e6e015eb41300a03ecf7d9fa55b0a85186bfe30af5be5aa68159e04ddd49101e95791a8e99c68bc23bd
7
+ data.tar.gz: 834b091feed593e873e06ce86b79931959ff98f868058a89bce89e43efe432d866dcb868ba3ec2e93306ae31b40a325228b272755c7c5e03c65894c7aaac16c9
@@ -1,5 +1,6 @@
1
1
  require 'confg/version'
2
2
  require 'confg/configuration'
3
+ require 'confg/erb_context'
3
4
 
4
5
  module Confg
5
6
 
@@ -9,6 +10,13 @@ module Confg
9
10
  @root ||= Pathname.new(calc_root_string).expand_path
10
11
  end
11
12
 
13
+ def erb_function(function_name, &block)
14
+ ::Confg::ErbContext.class_eval do
15
+ define_method(function_name, &block)
16
+ end
17
+ self
18
+ end
19
+
12
20
  def configure(raise_on_missed_key = false)
13
21
  @configuration ||= ::Confg::Configuration.new(raise_on_missed_key)
14
22
  yield @configuration if block_given?
@@ -1,5 +1,3 @@
1
- require 'yaml'
2
- require 'erb'
3
1
  require 'active_support/core_ext/module/delegation'
4
2
 
5
3
  module Confg
@@ -47,9 +45,11 @@ module Confg
47
45
 
48
46
  return unless raw_content
49
47
 
50
- raw_content = ERB.new(raw_content).result
51
- content = YAML.load(raw_content)
52
- content = content[Rails.env] if content.is_a?(::Hash) && content.has_key?(Rails.env)
48
+ ctxt = ::Confg::ErbContext.new
49
+ content = ctxt.evaluate(raw_content)
50
+
51
+ env = defined?(Rails) ? Rails.env.to_s : ENV["RAILS_ENV"] || ENV["RACK_ENV"]
52
+ content = content[Rails.env] if env && content.is_a?(::Hash) && content.has_key?(Rails.env)
53
53
 
54
54
  if key
55
55
  self.set(key, content)
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ require 'erb'
3
+
4
+ module Confg
5
+ class ErbContext
6
+
7
+ def evaluate(raw_content)
8
+ raw_content = ERB.new(raw_content).result(binding)
9
+ puts raw_content
10
+ YAML.load(raw_content)
11
+ end
12
+
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Confg
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-27 00:00:00.000000000 Z
11
+ date: 2017-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,7 @@ files:
38
38
  - confg.gemspec
39
39
  - lib/confg.rb
40
40
  - lib/confg/configuration.rb
41
+ - lib/confg/erb_context.rb
41
42
  - lib/confg/version.rb
42
43
  homepage: ''
43
44
  licenses: []