sysenv 0.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/sysenv.rb +1 -0
  3. data/lib/sysenv/sysenv.rb +33 -0
  4. metadata +69 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4040f5ae4654cb2d81c8071c5291422b19bb4ae7
4
+ data.tar.gz: cd93214b98f4913c6000453caf54f8aeab311672
5
+ SHA512:
6
+ metadata.gz: 6cce099aff52c9d5ccb9295c99cca80529db24af6026777ac8435ba634d437d9993444b0e7410570c386af6b2dbcbf61b541dd20e5d907c8aa475fb348c619a2
7
+ data.tar.gz: 08a4a3a2b3537873b2305ae0f75c2b064bed6ece87aea74d1ae6f7758b97b57db7030a3da70c5e5bc1836c75d1876d5ab0a88b0262813232e899d0b65947d001
@@ -0,0 +1 @@
1
+ require 'sysenv/sysenv'
@@ -0,0 +1,33 @@
1
+ require "active_support"
2
+
3
+ class Sysenv
4
+
5
+ # Override Project Specific Environment variables with system specific
6
+ #
7
+ # Example:
8
+ # >> sysenv = Sysenv.new
9
+ # >> sysenv.parse({api:{secret:{key: 'value',cert:'certificate'}}})
10
+ # => {api:{secret:{key: 'value',cert:'certificate'}}}
11
+ #
12
+ # Arguments:
13
+ # apply: (Hash)
14
+
15
+ def apply(hash, prefix=[])
16
+ envs = {} # hash of { underscorized env keys : normal env keys }
17
+ ENV.keys.collect { |e| envs[ActiveSupport::Inflector.underscore(e)] = e }
18
+ override_nested_hash(hash, envs, prefix)
19
+ end
20
+
21
+ def override_nested_hash(hash, envs={}, prefix=[])
22
+ hash.each do |key, value|
23
+ if value.class == Hash
24
+ hash[key] = override_nested_hash(value, envs, prefix.clone << key)
25
+ end
26
+ exp_key = (prefix.clone << key).join('_')
27
+ index = envs.keys.index(exp_key) || envs.keys.index(exp_key.to_sym)
28
+ hash[key] = ENV[envs.values[index]] if index
29
+ end
30
+ hash
31
+ end
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sysenv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Thaniyarasu Kannusamy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ description: |2
34
+ In Most Rails Application config/envs.yml file will be there , some
35
+ time we have to use System settings env values . so this gem is created, this
36
+ this will Override Project Envs with system envs
37
+ email: thaniyarasu@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/sysenv.rb
43
+ - lib/sysenv/sysenv.rb
44
+ homepage: https://github.com/thaniyarasu/sysenv
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.4.5
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Sysenv ! will load app envs and override with system envs
68
+ test_files: []
69
+ has_rdoc: