myconfig 1.0.0
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.
- checksums.yaml +7 -0
- data/lib/myconfig.rb +43 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d8a38a8389fe85b263c9084b9c9770224aa4196d97cbe4bdbdde8171f869ba89
|
|
4
|
+
data.tar.gz: dc476f3370e2a01ee180fb2fb8fce63a5e03b133efeb42cdf7ab97c6af678ff7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a92a350e023b8a28baf2bda3c96d9324c1aad49055a20b68d0712bd8986df4713d48fd64a7888a5cccb43af9fc970d47dc2a5d4dd229c3ce40a7087fba4f6557
|
|
7
|
+
data.tar.gz: 58f37121e9093c0440229fdd3de31012101ad8e9f92068bb63b654e06be619e7e48d4b49e953e43073efc3a259dec8bc2e058380c782885a2390da2ad38440de
|
data/lib/myconfig.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Class for reading configuration in YAML format
|
|
3
|
+
# argument: file name (with or without .yaml extension)
|
|
4
|
+
# look for config file with PREFIXES
|
|
5
|
+
|
|
6
|
+
require 'yaml'
|
|
7
|
+
|
|
8
|
+
class MyConfig
|
|
9
|
+
|
|
10
|
+
PREFIXES = %W(/etc/ /usr/local/etc/ #{ENV['HOME']}/etc/ #{ENV['HOME']}/. ./)
|
|
11
|
+
|
|
12
|
+
attr_reader :file, :conf
|
|
13
|
+
|
|
14
|
+
def initialize(config_name)
|
|
15
|
+
config_name = "#{config_name}.yaml" if config_name !~ /\.yaml$/
|
|
16
|
+
@conf = nil
|
|
17
|
+
@file = nil
|
|
18
|
+
PREFIXES.each do |inidir|
|
|
19
|
+
inifile = "#{inidir}#{config_name}"
|
|
20
|
+
c = parseinifile inifile
|
|
21
|
+
@conf = c if c
|
|
22
|
+
@file = inifile if c
|
|
23
|
+
end
|
|
24
|
+
if @conf.nil?
|
|
25
|
+
raise 'NoConfigFile'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def parseinifile(file)
|
|
30
|
+
if File.exist? file
|
|
31
|
+
YAML.load_file(file)
|
|
32
|
+
else
|
|
33
|
+
puts "can not open config file #{file}" if $DEBUG
|
|
34
|
+
nil
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# This method is a shortcut to accessing the @conf variable
|
|
39
|
+
def [](param)
|
|
40
|
+
@conf[param]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: myconfig
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Vladimir Horak
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: class for yaml configuration
|
|
14
|
+
email: vhor@cuni.cz
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/myconfig.rb
|
|
20
|
+
homepage: ''
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubygems_version: 3.2.3
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: My Config
|
|
43
|
+
test_files: []
|