configger_service 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/config_service.gemspec +17 -0
- data/lib/config_service.rb +17 -0
- data/lib/services/config_service.rb +30 -0
- data/lib/utils/hash_utils.rb +25 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6afb6b3525ef866fc5506c458c84320f1a11dcb
|
4
|
+
data.tar.gz: 8ed0dd8d986ebe99670dd3dae5d0b6d063e16f4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 178972b6cff232210871f8477049e1e5065fc3d66fef451274faa219b5b3c4a4711fee1c0ff0260ca36e53f0d2a785d60a2c2826b524d403b4cb43eb7812b512
|
7
|
+
data.tar.gz: 4f1ff9518460598b4e92ec4223e16404d9688e9616e2bdf0828854f5190c5af0be8d9a1c1920000526622fa16bbcc64769caa079db223cdb982e573ab40b2767
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'configger_service'
|
3
|
+
s.version = '1.0.5'
|
4
|
+
s.summary = "A gem to load config yml files"
|
5
|
+
s.description = "A gem to load config yml files"
|
6
|
+
s.authors = ['Linh Chau', 'John Thomas']
|
7
|
+
s.email = 'thomas07vt@gmail.com'
|
8
|
+
s.files = [
|
9
|
+
'./config_service.gemspec', 'lib/config_service.rb',
|
10
|
+
'lib/services/config_service.rb', 'lib/utils/hash_utils.rb'
|
11
|
+
]
|
12
|
+
s.homepage = 'https://github.com/thomas07vt/config_service'
|
13
|
+
s.license = 'MIT'
|
14
|
+
s.add_runtime_dependency 'logging'
|
15
|
+
s.add_runtime_dependency 'activesupport'
|
16
|
+
s.add_development_dependency 'rspec', '~> 3.1'
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'ostruct'
|
3
|
+
require_relative 'services/config_service'
|
4
|
+
|
5
|
+
def load_gem_lib(sub_path)
|
6
|
+
spec = Gem::Specification.find_by_name('config_service')
|
7
|
+
rb_files = Dir.glob("#{spec.gem_dir}/lib/#{sub_path}/*.rb")
|
8
|
+
rb_files.each { |rb_file| require rb_file }
|
9
|
+
rescue Exception => error
|
10
|
+
# Who cares?
|
11
|
+
end
|
12
|
+
|
13
|
+
['utils', 'services'].each do |sub_path|
|
14
|
+
load_gem_lib(sub_path)
|
15
|
+
rb_files = Dir.glob("#{File.expand_path('.')}/lib/#{sub_path}/*.rb")
|
16
|
+
rb_files.each { |rb_file| require rb_file }
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
class ConfigService
|
5
|
+
class << self
|
6
|
+
def load_config(config_file_name)
|
7
|
+
app_root = (defined? APP_ROOT)? APP_ROOT : File.expand_path('.')
|
8
|
+
|
9
|
+
config_file = nil
|
10
|
+
['conf', 'config'].each do |sub_path|
|
11
|
+
if File.exist?("#{app_root}/#{sub_path}/#{config_file_name}")
|
12
|
+
config_file = "#{app_root}/#{sub_path}/#{config_file_name}"
|
13
|
+
break
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
raise("#{Time.now.strftime("%m/%d/%Y %H:%M:%S.%3N %z")} ERROR: ConfigService#load_config #{config_file_name} file not found.") unless config_file
|
18
|
+
|
19
|
+
HashUtils.hash_to_open_struct(YAML.load_file(config_file))
|
20
|
+
end
|
21
|
+
|
22
|
+
def environment
|
23
|
+
return Rails.env if defined? Rails
|
24
|
+
return ENV['RACK_ENV'] if ENV['RACK_ENV'].present?
|
25
|
+
'development'
|
26
|
+
rescue => error
|
27
|
+
'development'
|
28
|
+
end
|
29
|
+
end # class methods
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class HashUtils
|
2
|
+
class << self
|
3
|
+
def hash_to_open_struct(data_hash)
|
4
|
+
elements_with_hash_values = data_hash.select { |key, value| value.is_a? Hash }
|
5
|
+
|
6
|
+
if elements_with_hash_values.empty?
|
7
|
+
result = OpenStruct.new(data_hash)
|
8
|
+
else
|
9
|
+
result = OpenStruct.new(data_hash.select { |key, value| !value.is_a?(Hash) })
|
10
|
+
elements_with_hash_values.each do |key, value|
|
11
|
+
result.send("#{key}=", hash_to_open_struct(value))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
result.extend(OpenStructHashable) if RUBY_PLATFORM == "java"
|
16
|
+
result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module OpenStructHashable
|
22
|
+
def [](val)
|
23
|
+
@table[val.to_sym]
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: configger_service
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Linh Chau
|
8
|
+
- John Thomas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: logging
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activesupport
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.1'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.1'
|
56
|
+
description: A gem to load config yml files
|
57
|
+
email: thomas07vt@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- "./config_service.gemspec"
|
63
|
+
- lib/config_service.rb
|
64
|
+
- lib/services/config_service.rb
|
65
|
+
- lib/utils/hash_utils.rb
|
66
|
+
homepage: https://github.com/thomas07vt/config_service
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.4.6
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: A gem to load config yml files
|
90
|
+
test_files: []
|