convert_global_env 1.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/USAGE.md +15 -0
- data/convert_global_env.gemspec +43 -0
- data/lib/convert_global_env/autoinclude.rb +7 -0
- data/lib/convert_global_env/constants.rb +35 -0
- data/lib/convert_global_env/convert_global_env.rb +50 -0
- data/lib/convert_global_env/module_methods.rb +99 -0
- data/lib/convert_global_env/version/version.rb +12 -0
- data/lib/convert_global_env.rb +5 -0
- data/test/testing_convert_global_env.rb +32 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ac7e018f41eaa7c3885cd5cfd4ba985855b605b9f55b9fcb317b506f1f1455df
|
4
|
+
data.tar.gz: da72334315082fc1c08170cd1d54c79084765788f98b53956ed9c4f3dd9268cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfe29d3a7d97dfd915aa60d6cf580e08aeb1a1f21a8b44618714503338ec70759bc767729c3de4ccef6fb03ae59205669bd64734d815c104c9ba1275baf860f2
|
7
|
+
data.tar.gz: 46ef439da618cc6f5292db01dc3e842eebb65026756985b9d94c96e6ea37865a7fb10a69c72a239495620a7829a58ac9d3ff36bd9c2eb5bfc955aea517611a6e
|
data/USAGE.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
= Usage of Library
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
This small module converts a $FOO variable into an
|
6
|
+
ENV variable.
|
7
|
+
|
8
|
+
== Requiring it
|
9
|
+
|
10
|
+
require 'convert_global_env'
|
11
|
+
|
12
|
+
== Using it in a project
|
13
|
+
|
14
|
+
ConvertGlobalEnv.convert('$FOO/BAR')
|
15
|
+
ConvertGlobalEnv['$FOO/BAR']
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# =========================================================================== #
|
2
|
+
# Gemspec for Project ConvertGlobalEnv.
|
3
|
+
# =========================================================================== #
|
4
|
+
require 'convert_global_env/version/version.rb'
|
5
|
+
require 'roebe'
|
6
|
+
|
7
|
+
Gem::Specification.new { |s|
|
8
|
+
|
9
|
+
s.name = 'convert_global_env'
|
10
|
+
s.version = ConvertGlobalEnv::VERSION
|
11
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
12
|
+
|
13
|
+
s.summary = <<-EOF
|
14
|
+
|
15
|
+
This module translates a string like $FOO/bar into the corresponding
|
16
|
+
ENV variable, i.e. ENV['FOO']+'/bar'.
|
17
|
+
It has no external dependencies.
|
18
|
+
|
19
|
+
EOF
|
20
|
+
|
21
|
+
s.description = <<-EOF
|
22
|
+
|
23
|
+
This module translates a string like $FOO/bar into the corresponding
|
24
|
+
ENV variable, i.e. ENV['FOO']+'/bar'.
|
25
|
+
It has no external dependencies.
|
26
|
+
|
27
|
+
EOF
|
28
|
+
|
29
|
+
s.extra_rdoc_files = %w(
|
30
|
+
USAGE.md
|
31
|
+
)
|
32
|
+
|
33
|
+
s.authors = ['Robert A. Heiler']
|
34
|
+
s.email = Roebe.email?
|
35
|
+
s.files = Dir['**/*']
|
36
|
+
s.licenses = 'GPL-2.0'
|
37
|
+
s.homepage = 'https://rubygems.org/gems/convert_global_env'
|
38
|
+
|
39
|
+
s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
|
40
|
+
s.required_rubygems_version = '>= '+Gem::VERSION
|
41
|
+
s.rubygems_version = '>= '+Gem::VERSION
|
42
|
+
|
43
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module ConvertGlobalEnv
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === ENCODING_ISO
|
9
|
+
# ========================================================================= #
|
10
|
+
ENCODING_ISO = 'ISO-8859-1'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === ENCODING_UTF
|
14
|
+
# ========================================================================= #
|
15
|
+
ENCODING_UTF = 'UTF-8'
|
16
|
+
|
17
|
+
# ========================================================================= #
|
18
|
+
# === ConvertGlobalEnv::USE_THIS_ENCODING
|
19
|
+
# ========================================================================= #
|
20
|
+
USE_THIS_ENCODING = ENCODING_UTF
|
21
|
+
|
22
|
+
# ========================================================================= #
|
23
|
+
# === REGEX_TO_CHECK_FOR_GLOBAL_ENV
|
24
|
+
#
|
25
|
+
# The regex to check for the global env.
|
26
|
+
#
|
27
|
+
# See:
|
28
|
+
#
|
29
|
+
# https://rubular.com/r/tTX6lVBpSa
|
30
|
+
#
|
31
|
+
# ========================================================================= #
|
32
|
+
REGEX_TO_CHECK_FOR_GLOBAL_ENV =
|
33
|
+
/\$([A-Za-z_]+)+/
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# How would you use this software in your project?
|
6
|
+
#
|
7
|
+
# Well, first require it:
|
8
|
+
#
|
9
|
+
# require 'convert_global_env'
|
10
|
+
#
|
11
|
+
# Then, feed it the string that contains a '$' character, like so:
|
12
|
+
#
|
13
|
+
# ConvertGlobalEnv.convert '$SRC/RUBY'
|
14
|
+
#
|
15
|
+
# =========================================================================== #
|
16
|
+
module ConvertGlobalEnv
|
17
|
+
|
18
|
+
require 'convert_global_env/module_methods.rb'
|
19
|
+
require 'convert_global_env/constants.rb'
|
20
|
+
require 'convert_global_env/version/version.rb'
|
21
|
+
|
22
|
+
alias e puts
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === @report_errors
|
26
|
+
# ========================================================================= #
|
27
|
+
@report_errors = true
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === @use_this_target_encoding
|
31
|
+
#
|
32
|
+
# This denotes the encoding in use. If we use the wrong encoding
|
33
|
+
# then failures may happen.
|
34
|
+
#
|
35
|
+
# Since as of 28.08.2020 we will default to UTF as encoding.
|
36
|
+
# ========================================================================= #
|
37
|
+
@use_this_target_encoding = USE_THIS_ENCODING
|
38
|
+
|
39
|
+
# ========================================================================= #
|
40
|
+
# === ConvertGlobalEnv.encoding?
|
41
|
+
# ========================================================================= #
|
42
|
+
def self.encoding?
|
43
|
+
@use_this_target_encoding
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
if __FILE__ == $PROGRAM_NAME
|
49
|
+
puts ConvertGlobalEnv.convert(ARGV.first)
|
50
|
+
end # cgenv
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module ConvertGlobalEnv
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === ConvertGlobalEnv.filename?
|
9
|
+
# ========================================================================= #
|
10
|
+
def self.filename?
|
11
|
+
_ = 'convert_global_env.rb'
|
12
|
+
_ = sfancy(_) if Object.const_defined? :Colours
|
13
|
+
_ # This is the result.
|
14
|
+
end
|
15
|
+
|
16
|
+
# ========================================================================= #
|
17
|
+
# === ConvertGlobalEnv.e
|
18
|
+
# ========================================================================= #
|
19
|
+
def self.e(i = '')
|
20
|
+
puts i
|
21
|
+
end
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === ConvertGlobalEnv.report_errors?
|
25
|
+
# ========================================================================= #
|
26
|
+
def self.report_errors?
|
27
|
+
@report_errors
|
28
|
+
end
|
29
|
+
|
30
|
+
# ========================================================================= #
|
31
|
+
# === ConvertGlobalEnv.be_quiet
|
32
|
+
# ========================================================================= #
|
33
|
+
def self.be_quiet
|
34
|
+
@report_errors = false
|
35
|
+
end
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === ConvertGlobalEnv[]
|
39
|
+
#
|
40
|
+
# Easier conversion variant. Will also honour the @report_errors
|
41
|
+
# class-instance variable.
|
42
|
+
# ========================================================================= #
|
43
|
+
def self.[](i)
|
44
|
+
ConvertGlobalEnv.convert(i, ConvertGlobalEnv.report_errors?)
|
45
|
+
end
|
46
|
+
|
47
|
+
# ========================================================================= #
|
48
|
+
# === ConvertGlobalEnv.convert(i)
|
49
|
+
#
|
50
|
+
# Use this method to convert from $FOO to ENV['FOO'], if $FOO exists.
|
51
|
+
#
|
52
|
+
# Specific usage examples:
|
53
|
+
#
|
54
|
+
# ConvertGlobalEnv.convert '$SRC/RUBY'
|
55
|
+
# ConvertGlobalEnv.convert '$MY_SRC/RUBY'
|
56
|
+
#
|
57
|
+
# ========================================================================= #
|
58
|
+
def self.convert(
|
59
|
+
i,
|
60
|
+
shall_we_report_errors = ConvertGlobalEnv.report_errors?
|
61
|
+
)
|
62
|
+
if shall_we_report_errors == :do_not_report_errors
|
63
|
+
shall_we_report_errors = false
|
64
|
+
end
|
65
|
+
if i.is_a? Array
|
66
|
+
i.map {|entry|
|
67
|
+
ConvertGlobalEnv.convert(entry, shall_we_report_errors)
|
68
|
+
} # Call recursively here.
|
69
|
+
else # Here come strings only.
|
70
|
+
# i.sub!(/\{/, '') # get rid of any { - Not a good idea. Disabled Sep 2012.
|
71
|
+
# i.sub!(/\}/, '') # get rid of any }
|
72
|
+
# ===================================================================== #
|
73
|
+
# We prefer ISO encoding here. No, we no longer do as of August 2020.
|
74
|
+
# ===================================================================== #
|
75
|
+
# case i.encoding.to_s
|
76
|
+
# # =================================================================== #
|
77
|
+
# # === ENCODING_UTF
|
78
|
+
# # =================================================================== #
|
79
|
+
# when ENCODING_UTF
|
80
|
+
# i = i.dup if i.frozen?
|
81
|
+
# i = i.force_encoding(ENCODING_ISO)
|
82
|
+
# end if File.exist?(i.to_s) # But only if the file exists.
|
83
|
+
unless i.encoding.to_s == ConvertGlobalEnv.encoding?
|
84
|
+
i = i.dup if i.frozen?
|
85
|
+
i = i.force_encoding(ConvertGlobalEnv.encoding?)
|
86
|
+
end
|
87
|
+
i =~ REGEX_TO_CHECK_FOR_GLOBAL_ENV # defined in this file here.
|
88
|
+
if $1 and ENV[$1]
|
89
|
+
i = i.to_s.dup # We want a clean String here.
|
90
|
+
i.gsub!("$#{$1}", ENV[$1]) unless ENV[$1].nil? # + "#{$2}"
|
91
|
+
else # Do nothing, except if you wish to debug.
|
92
|
+
# puts "The input: #{i} does not match against `#{REGEX_TO_CHECK_FOR_GLOBAL_ENV}`"
|
93
|
+
# pp $1; pp ENV[$1]
|
94
|
+
end
|
95
|
+
return i
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module ConvertGlobalEnv
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === ConvertGlobalEnv::VERSION
|
9
|
+
# ========================================================================= #
|
10
|
+
VERSION = '1.0.23'
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'colours/colours_e_autoinclude.rb'
|
6
|
+
require 'convert_global_env/autoinclude'
|
7
|
+
|
8
|
+
input = '$BIORUBY/bioshell/bio_shell.rb'
|
9
|
+
|
10
|
+
e
|
11
|
+
e 'Now testing some stuff. (Note that some of the variables will not exist.)'
|
12
|
+
e
|
13
|
+
e 'First, we test '+sfancy(input)
|
14
|
+
e ' -> '+ConvertGlobalEnv.convert(input)
|
15
|
+
e ' -> '+ConvertGlobalEnv.convert('test $IMG/rubyconvention2012')
|
16
|
+
e ' -> '+ConvertGlobalEnv.convert('$SRC/RUBY')
|
17
|
+
e ' -> '+ConvertGlobalEnv.convert('$T ee')
|
18
|
+
e ' -> '+ConvertGlobalEnv.convert('$MY_PHP')
|
19
|
+
e ' -> '+ConvertGlobalEnv.convert('--enable-bcmath --enable-calendar '\
|
20
|
+
'--enable-cli --enable-dba=shared --enable-fastcgi --enable-force-redirect '\
|
21
|
+
'--enable-force-cgi-redirect --enable-inline-optimization '\
|
22
|
+
'--with-config-file-path=$MY_PHP '\
|
23
|
+
'--with-iconv-dir=/Programs/Libiconv/Current/ '\
|
24
|
+
'--with-gdbm --with-gmp --without-gd '\
|
25
|
+
'--without-iconv --without-sqlite --disable-debug')
|
26
|
+
e
|
27
|
+
e "Next, we test Array as input, aka: %w( a b c )+['$MY_SRC/RUBY']:"
|
28
|
+
e
|
29
|
+
this_array = %w( a b c ) + ['$MY_SRC/RUBY']
|
30
|
+
this_array = ConvertGlobalEnv.convert(this_array)
|
31
|
+
e ' -> '+this_array.join("\n")
|
32
|
+
e
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: convert_global_env
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.23
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert A. Heiler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |2+
|
14
|
+
|
15
|
+
This module translates a string like $FOO/bar into the corresponding
|
16
|
+
ENV variable, i.e. ENV['FOO']+'/bar'.
|
17
|
+
It has no external dependencies.
|
18
|
+
|
19
|
+
email: shevy@inbox.lt
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files:
|
23
|
+
- USAGE.md
|
24
|
+
files:
|
25
|
+
- USAGE.md
|
26
|
+
- convert_global_env.gemspec
|
27
|
+
- lib/convert_global_env.rb
|
28
|
+
- lib/convert_global_env/autoinclude.rb
|
29
|
+
- lib/convert_global_env/constants.rb
|
30
|
+
- lib/convert_global_env/convert_global_env.rb
|
31
|
+
- lib/convert_global_env/module_methods.rb
|
32
|
+
- lib/convert_global_env/version/version.rb
|
33
|
+
- test/testing_convert_global_env.rb
|
34
|
+
homepage: https://rubygems.org/gems/convert_global_env
|
35
|
+
licenses:
|
36
|
+
- GPL-2.0
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.5.8
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 3.2.24
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.2.24
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: This module translates a string like $FOO/bar into the corresponding ENV
|
57
|
+
variable, i.e. ENV['FOO']+'/bar'. It has no external dependencies.
|
58
|
+
test_files: []
|
59
|
+
...
|