convert_global_env 1.0.23 → 1.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac7e018f41eaa7c3885cd5cfd4ba985855b605b9f55b9fcb317b506f1f1455df
4
- data.tar.gz: da72334315082fc1c08170cd1d54c79084765788f98b53956ed9c4f3dd9268cf
3
+ metadata.gz: e12c6410d7213a21f33a500e1cf55d487c2d5c7154518cd757611b1a12f38590
4
+ data.tar.gz: ca8fdc0ff0e32ecffe6597d17440a7cb11620a753741fd928c3bcfe8f6abeaf3
5
5
  SHA512:
6
- metadata.gz: dfe29d3a7d97dfd915aa60d6cf580e08aeb1a1f21a8b44618714503338ec70759bc767729c3de4ccef6fb03ae59205669bd64734d815c104c9ba1275baf860f2
7
- data.tar.gz: 46ef439da618cc6f5292db01dc3e842eebb65026756985b9d94c96e6ea37865a7fb10a69c72a239495620a7829a58ac9d3ff36bd9c2eb5bfc955aea517611a6e
6
+ metadata.gz: dbb0af91e1430cef7282c0a9ce574aa0c084a42e1539caadc7aeb405d4ced5b1163eb9863211a26324ad7fad06392fb77e3ef2c809940461b742749164e4bec8
7
+ data.tar.gz: 0d70ea11eb9cfbc789f10b9913d27eca700aadf78a4fca809ee6a8114195a883665014b51f0712306f2fce8a45cfeed3d1fd8155bafb289053e6ee87a9b88a8a
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ [![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
2
+ [![forthebadge](http://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
3
+ [![Gem Version](https://badge.fury.io/rb/convert_global_env.svg)](https://badge.fury.io/rb/convert_global_env)
4
+
5
+ <img src="https://i.imgur.com/64icv2h.png" style="margin: 1em; margin-left: 5em">
6
+
7
+ ## About the convert_global_env project
8
+
9
+ This project can convert string entries such as $FOO to
10
+ their corresponding ENV['FOO'] counterpart. This will
11
+ happen on a whole string, so multiple entries of $FOO
12
+ can be replaced in one go.
13
+
14
+ The project was created so that I can batch-generate hardcoded shell
15
+ variables or query the value of ENV variables from .cgi files and
16
+ elsewhere.
17
+
18
+ In **May 2022** when this project was rewritten, support for
19
+ hashes other than the one stored in ENV was added too. This
20
+ will allow us to properly work on windows as well, should ENV **not**
21
+ contain any such values (if the **rcfiles** gem is available).
22
+
23
+ ## Structure of the convert_global_env gem
24
+
25
+ This subsection contains just a few noteworthy comments pertaining to the
26
+ structure of this gem.
27
+
28
+ ## How to use the convert_global_env gem in your project
29
+
30
+ There are several different ways how this gem can be used, but let's
31
+ describe the simplest variant.
32
+
33
+ First, require it via:
34
+
35
+ require 'convert_global_env'
36
+
37
+ Then, if your input-string contains a '$' character, convert it like
38
+ so:
39
+
40
+ ConvertGlobalEnv.convert '$MY_SRC/ruby' # => "/home/x/src/ruby"
41
+
42
+ Note that this **only** works if your ENV (environment) contains such
43
+ a value. So if the value $MY_SRC is not defined then the above logically
44
+ will not work.
45
+
46
+ This can be a problem for some situations, such as in a .cgi file where
47
+ no ENV variables exist, or on windows typically. For these reasons an
48
+ alternative exists, if the **rcfile** gem is installed and available.
49
+
50
+ ## The method load_values_from_the_rcfiles_gem()
51
+
52
+ The method load_values_from_the_rcfiles_gem() is normally not used,
53
+ but you can use it specifically to load ENV-like variables if the
54
+ **rcfiles** gem is installed.
55
+
56
+ See the .cgi page in the test/ subdirectory at:
57
+
58
+ convert_global_env/test/testing_cgi_environment.cgi
59
+
60
+ ## Licence
61
+
62
+ In **January** of **2022** the licence of this gem was changed to MIT. The
63
+ primary reason for this is because this gem is used by several other gems
64
+ which are mostly MIT-based. So it seemed simpler to have the same licence
65
+ for this gem as well.
66
+
67
+
68
+ ## Contact information
69
+
70
+ If your creative mind has ideas and specific suggestions to make this
71
+ gem more useful in general, feel free to drop me an email at any
72
+ time, via:
73
+
74
+ shevy@inbox.lt
75
+
76
+ Before that email I used an email account at Google gmail, but in **2021** I
77
+ decided to slowly abandon gmail for various reasons. In part this is because
78
+ the UI annoys me (on non-chrome browser loading takes too long), but also
79
+ because of Google's attempt to establish mass surveillance via its
80
+ federated cohorts sniffing (FLoC). I do not know what happened at Google,
81
+ but enough is enough - there is only so much you can take while supporting
82
+ greed. When it comes to data mining done by private groups, ultimately
83
+ the user became the product.
84
+
85
+ Do keep in mind that responding to emails may take some time,
86
+ depending on the amount of work I may have at that moment, due
87
+ to reallife time constraints. I will, however had, read feedback
88
+ eventually. Patches and code changes are welcome too, of course,
89
+ as long as they are in the spirit of the project at hand, e. g.
90
+ fitting to the general theme. For this I may make use of github
91
+ as a discussion site, but this has a low priority right now.
92
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'convert_global_env'
6
+
7
+ puts ConvertGlobalEnv[ARGV]
@@ -2,38 +2,29 @@
2
2
  # Gemspec for Project ConvertGlobalEnv.
3
3
  # =========================================================================== #
4
4
  require 'convert_global_env/version/version.rb'
5
- require 'roebe'
5
+ require 'roebe/toplevel_methods/misc.rb'
6
6
 
7
7
  Gem::Specification.new { |s|
8
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
9
+ s.name = 'convert_global_env'
10
+ s.version = ConvertGlobalEnv::VERSION
11
+ s.date = Time.now.strftime('%Y-%m-%d')
14
12
 
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.
13
+ DESCRIPTION = <<-EOF
18
14
 
19
- EOF
20
-
21
- s.description = <<-EOF
15
+ This module translates a string like $FOO/bar into the corresponding
16
+ ENV variable, i.e. ENV['FOO']+'/bar'. This gem has no external
17
+ dependencies.
22
18
 
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.
19
+ EOF
26
20
 
27
- EOF
28
-
29
- s.extra_rdoc_files = %w(
30
- USAGE.md
31
- )
21
+ s.summary = DESCRIPTION
22
+ s.description = DESCRIPTION
32
23
 
33
24
  s.authors = ['Robert A. Heiler']
34
25
  s.email = Roebe.email?
35
26
  s.files = Dir['**/*']
36
- s.licenses = 'GPL-2.0'
27
+ s.licenses = 'MIT'
37
28
  s.homepage = 'https://rubygems.org/gems/convert_global_env'
38
29
 
39
30
  s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
data/doc/README.gen ADDED
@@ -0,0 +1,65 @@
1
+ ADD_RUBY_HEADER
2
+
3
+ <img src="https://i.imgur.com/64icv2h.png" style="margin: 1em; margin-left: 5em">
4
+
5
+ ## About the convert_global_env project
6
+
7
+ This project can convert string entries such as $FOO to
8
+ their corresponding ENV['FOO'] counterpart. This will
9
+ happen on a whole string, so multiple entries of $FOO
10
+ can be replaced in one go.
11
+
12
+ The project was created so that I can batch-generate hardcoded shell
13
+ variables or query the value of ENV variables from .cgi files and
14
+ elsewhere.
15
+
16
+ In **May 2022** when this project was rewritten, support for
17
+ hashes other than the one stored in ENV was added too. This
18
+ will allow us to properly work on windows as well, should ENV **not**
19
+ contain any such values (if the **rcfiles** gem is available).
20
+
21
+ ## Structure of the convert_global_env gem
22
+
23
+ This subsection contains just a few noteworthy comments pertaining to the
24
+ structure of this gem.
25
+
26
+ ## How to use the convert_global_env gem in your project
27
+
28
+ There are several different ways how this gem can be used, but let's
29
+ describe the simplest variant.
30
+
31
+ First, require it via:
32
+
33
+ require 'convert_global_env'
34
+
35
+ Then, if your input-string contains a '$' character, convert it like
36
+ so:
37
+
38
+ ConvertGlobalEnv.convert '$MY_SRC/ruby' # => "/home/x/src/ruby"
39
+
40
+ Note that this **only** works if your ENV (environment) contains such
41
+ a value. So if the value $MY_SRC is not defined then the above logically
42
+ will not work.
43
+
44
+ This can be a problem for some situations, such as in a .cgi file where
45
+ no ENV variables exist, or on windows typically. For these reasons an
46
+ alternative exists, if the **rcfile** gem is installed and available.
47
+
48
+ ## The method load_values_from_the_rcfiles_gem()
49
+
50
+ The method load_values_from_the_rcfiles_gem() is normally not used,
51
+ but you can use it specifically to load ENV-like variables if the
52
+ **rcfiles** gem is installed.
53
+
54
+ See the .cgi page in the test/ subdirectory at:
55
+
56
+ convert_global_env/test/testing_cgi_environment.cgi
57
+
58
+ ## Licence
59
+
60
+ In **January** of **2022** the licence of this gem was changed to MIT. The
61
+ primary reason for this is because this gem is used by several other gems
62
+ which are mostly MIT-based. So it seemed simpler to have the same licence
63
+ for this gem as well.
64
+
65
+ ADD_CONTACT_INFORMATION
@@ -2,6 +2,6 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
- require 'convert_global_env/convert_global_env.rb'
5
+ require 'convert_global_env/class/convert_global_env.rb'
6
6
 
7
- include ConvertGlobalEnv
7
+ include ConvertGlobalEnv # Include the toplevel module namespace here.
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === ConvertGlobalEnv::ConvertGlobalEnv
6
+ #
7
+ # Usage example:
8
+ #
9
+ # ConvertGlobalEnv::ConvertGlobalEnv.new(ARGV)
10
+ #
11
+ # =========================================================================== #
12
+ # require 'convert_global_env/class/convert_global_env.rb'
13
+ # =========================================================================== #
14
+ module ConvertGlobalEnv
15
+
16
+ class ConvertGlobalEnv # === ConvertGlobalEnv::ConvertGlobalEnv
17
+
18
+ alias e puts
19
+
20
+ require 'convert_global_env/constants/constants.rb'
21
+ require 'convert_global_env/version/version.rb'
22
+ require 'convert_global_env/toplevel_methods/toplevel_methods.rb'
23
+
24
+ # ========================================================================= #
25
+ # === initialize
26
+ # ========================================================================= #
27
+ def initialize(
28
+ i = ARGV,
29
+ run_already = true
30
+ )
31
+ reset
32
+ set_input_string(i)
33
+ run if run_already
34
+ end
35
+
36
+ # ========================================================================= #
37
+ # === reset (reset tag)
38
+ # ========================================================================= #
39
+ def reset
40
+ # ======================================================================= #
41
+ # === @translated_string
42
+ # ======================================================================= #
43
+ @translated_string = ''.dup
44
+ # ======================================================================= #
45
+ # === @hash_containing_the_environment_values
46
+ #
47
+ # This Hash can also be different, but by default it will refer to
48
+ # the ENV variable.
49
+ # ======================================================================= #
50
+ @hash_containing_the_environment_values = ENV
51
+ end
52
+
53
+ # ========================================================================= #
54
+ # === hash_containing_the_environment_values?
55
+ # ========================================================================= #
56
+ def hash_containing_the_environment_values?
57
+ @hash_containing_the_environment_values
58
+ end; alias hash? hash_containing_the_environment_values? # === hash?
59
+
60
+ # ========================================================================= #
61
+ # === load_values_from_the_rcfiles_gem
62
+ #
63
+ # Only call this method if the rcfiles gem is installed, and if you really
64
+ # want to use the values from the .yml file that is contained in the
65
+ # rcfiles gem.
66
+ # ========================================================================= #
67
+ def load_values_from_the_rcfiles_gem
68
+ require 'rcfiles'
69
+ @hash_containing_the_environment_values = YAML.load_file(Rcfiles.file_global_variables)
70
+ end; alias load_custom_file load_values_from_the_rcfiles_gem # === load_custom_file
71
+
72
+ # ========================================================================= #
73
+ # === set_input_string
74
+ # ========================================================================= #
75
+ def set_input_string(i = '')
76
+ i = [i].flatten.compact.join(' ').strip
77
+ unless i.encoding.to_s == ::ConvertGlobalEnv.encoding?
78
+ i = i.dup if i.frozen?
79
+ i = i.force_encoding(::ConvertGlobalEnv.encoding?)
80
+ end
81
+ @input_string = i
82
+ end
83
+
84
+ # ========================================================================= #
85
+ # === input_string?
86
+ # ========================================================================= #
87
+ def input_string?
88
+ @input_string
89
+ end; alias input? input_string? # === input?
90
+
91
+ # ========================================================================= #
92
+ # === regex_to_use?
93
+ #
94
+ # Refer to the main regex for this project.
95
+ # ========================================================================= #
96
+ def regex_to_use?
97
+ REGEX_TO_CHECK_FOR_GLOBAL_ENV
98
+ end; alias main_regex? regex_to_use? # === main_regex?
99
+
100
+ # ========================================================================= #
101
+ # === run (run tag)
102
+ # ========================================================================= #
103
+ def run
104
+ do_the_conversion
105
+ end
106
+
107
+ # ========================================================================= #
108
+ # === do_the_conversion
109
+ #
110
+ # This is the method that does the actual conversion.
111
+ # ========================================================================= #
112
+ def do_the_conversion(
113
+ input = input_string?
114
+ )
115
+ regex = regex_to_use?
116
+ @translated_string = input.dup # Keep a reference copy here.
117
+ if input.include? '$'
118
+ input =~ regex
119
+ this_env_was_found = $1.to_s.dup
120
+ # ===================================================================== #
121
+ # Next check whether our main hash contains these environment
122
+ # values or not.
123
+ # ===================================================================== #
124
+ if @hash_containing_the_environment_values.include? this_env_was_found
125
+ @translated_string = input.gsub(
126
+ /#{this_env_was_found}/,
127
+ @hash_containing_the_environment_values[this_env_was_found]
128
+ ).delete('$')
129
+ end
130
+ end
131
+ return @translated_string
132
+ end; alias convert do_the_conversion # === convert
133
+
134
+ # ========================================================================= #
135
+ # === translated_string?
136
+ # ========================================================================= #
137
+ def translated_string?
138
+ @translated_string
139
+ end; alias result? translated_string? # === result?
140
+
141
+ # ========================================================================= #
142
+ # === ConvertGlobalEnv::ConvertGlobalEnv[]
143
+ #
144
+ # Usage example:
145
+ #
146
+ # x = ConvertGlobalEnv::ConvertGlobalEnv['umount $USB3']
147
+ #
148
+ # ========================================================================= #
149
+ def self.[](i = '')
150
+ new(i)
151
+ end
152
+
153
+ end; end
154
+
155
+ if __FILE__ == $PROGRAM_NAME
156
+ ConvertGlobalEnv::ConvertGlobalEnv.new(ARGV)
157
+ end # rawconvertglobalenv umount $USB3
@@ -2,6 +2,8 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
+ # require 'convert_global_env/constants/constants.rb'
6
+ # =========================================================================== #
5
7
  module ConvertGlobalEnv
6
8
 
7
9
  # ========================================================================= #
@@ -16,6 +18,9 @@ module ConvertGlobalEnv
16
18
 
17
19
  # ========================================================================= #
18
20
  # === ConvertGlobalEnv::USE_THIS_ENCODING
21
+ #
22
+ # This constant denotes the default encoding that is used for the
23
+ # ConvertGlobalEnv namespace.
19
24
  # ========================================================================= #
20
25
  USE_THIS_ENCODING = ENCODING_UTF
21
26
 
@@ -26,10 +31,11 @@ module ConvertGlobalEnv
26
31
  #
27
32
  # See:
28
33
  #
29
- # https://rubular.com/r/tTX6lVBpSa
34
+ # https://rubular.com/r/6oyCjKnaOZd8rz
30
35
  #
31
36
  # ========================================================================= #
32
37
  REGEX_TO_CHECK_FOR_GLOBAL_ENV =
33
- /\$([A-Za-z_]+)+/
38
+ /\$\{?([A-Za-z_0-9]+)\}?/
39
+ # The old regex was: /\$\{?([A-Za-z_]+)\}?/
34
40
 
35
41
  end
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'convert_global_env/toplevel_methods/toplevel_methods.rb'
6
+ # =========================================================================== #
7
+ module ConvertGlobalEnv
8
+
9
+ # ========================================================================= #
10
+ # === @use_this_target_encoding
11
+ #
12
+ # This denotes the encoding in use. If we use the wrong encoding
13
+ # then failures may happen.
14
+ #
15
+ # Since as of 28.08.2020 we will default to UTF as encoding.
16
+ # ========================================================================= #
17
+ @use_this_target_encoding = USE_THIS_ENCODING
18
+
19
+ # ========================================================================= #
20
+ # === ConvertGlobalEnv.encoding?
21
+ # ========================================================================= #
22
+ def self.encoding?
23
+ @use_this_target_encoding
24
+ end
25
+
26
+ # ========================================================================= #
27
+ # === ConvertGlobalEnv.e
28
+ # ========================================================================= #
29
+ def self.e(i = '')
30
+ puts i
31
+ end
32
+
33
+ # ========================================================================= #
34
+ # === ConvertGlobalEnv.filename?
35
+ # ========================================================================= #
36
+ def self.filename?
37
+ _ = 'convert_global_env.rb'
38
+ _ = sfancy(_) if Object.const_defined? :Colours
39
+ return _ # This is the result.
40
+ end
41
+
42
+ # ========================================================================= #
43
+ # === ConvertGlobalEnv[]
44
+ #
45
+ # This variant must always return the result, as-is.
46
+ # ========================================================================= #
47
+ def self.[](i = ARGV)
48
+ ::ConvertGlobalEnv::ConvertGlobalEnv[i].result?
49
+ end; self.instance_eval { alias convert [] } # === ConvertGlobalEnv.convert
50
+
51
+ # ========================================================================= #
52
+ # === ConvertGlobalEnv.new
53
+ #
54
+ # This is different in that it must always return a new instance of the
55
+ # ConvertGlobalEnv class itself.
56
+ # ========================================================================= #
57
+ def self.new(i = ARGV)
58
+ ::ConvertGlobalEnv::ConvertGlobalEnv.new(i)
59
+ end
60
+
61
+ end
@@ -2,11 +2,13 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
+ # require 'convert_global_env/version/version.rb'
6
+ # =========================================================================== #
5
7
  module ConvertGlobalEnv
6
8
 
7
9
  # ========================================================================= #
8
10
  # === ConvertGlobalEnv::VERSION
9
11
  # ========================================================================= #
10
- VERSION = '1.0.23'
12
+ VERSION = '1.1.4'
11
13
 
12
14
  end
@@ -2,4 +2,4 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
- require 'convert_global_env/convert_global_env.rb'
5
+ require 'convert_global_env/class/convert_global_env.rb'
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # http://localhost/programming/ruby/src/convert_global_env/test/testing_cgi_environment.cgi
6
+ # =========================================================================== #
7
+ require 'cgi'
8
+ require 'convert_global_env'
9
+
10
+ alias e puts
11
+
12
+ cgi = CGI.new 'html4' # Create a cgi object, with HTML 4 generation methods.
13
+ e cgi.header
14
+
15
+ e '<html><body>This is a simple test for the ENV variable.<br><br>
16
+ First, we show how many variables are contained in ENV:'
17
+
18
+ e ENV.keys.size.to_s+' entries <br><br>'
19
+ e 'Evidently this does not contain the ENV I normally use.<br>
20
+ For instance, $PROGRAMMING is not defined, so this
21
+ will not yield anything: '+ConvertGlobalEnv['$PROGRAMMING'].to_s
22
+ e '<br><br><hr>But now we will load support for my custom ENV:'
23
+ _ = ConvertGlobalEnv.new
24
+ _.load_custom_file
25
+ e '<br><hr>And now, magically, $PROGRAMMING is defined \o/: '+
26
+ _.convert('$PROGRAMMING').to_s
27
+ e '</body></html>'
@@ -2,31 +2,61 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
- require 'colours/colours_e_autoinclude.rb'
6
- require 'convert_global_env/autoinclude'
5
+ require 'colours/autoinclude'
6
+ require 'convert_global_env'
7
7
 
8
- input = '$BIORUBY/bioshell/bio_shell.rb'
8
+ # =========================================================================== #
9
+ # === cliner
10
+ # =========================================================================== #
11
+ def cliner
12
+ e '='*80
13
+ end
9
14
 
15
+ print rev
16
+ cliner
10
17
  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']:"
18
+ e steelblue('Next testing the gem called "convert_global_env".')
19
+ e steelblue('Keep in mind that not all tested input will cause a replacement to happen.')
20
+ e steelblue('Thus, some test-cases will appear the same rather than show a difference.')
21
+ e steelblue('In these cases the $VARIABLE does not exist, hence why nothing could be replaced.')
28
22
  e
29
- this_array = %w( a b c ) + ['$MY_SRC/RUBY']
30
- this_array = ConvertGlobalEnv.convert(this_array)
31
- e ' -> '+this_array.join("\n")
23
+ # =========================================================================== #
24
+ # The next array is the input we want to test against.
25
+ # =========================================================================== #
26
+ array_test_this_input = [
27
+ 'umount $USB3',
28
+ 'umount $USB3EGGGGGGGGGG',
29
+ '$BIORUBY/bioshell/bio_shell.rb',
30
+ 'test $IMG/rubyconvention2012',
31
+ '$SRC/ruby',
32
+ '$MY_SRC/ruby',
33
+ '$T ee',
34
+ '$MY_PHP',
35
+ '$USB3',
36
+ 'umount $USB3',
37
+ '--enable-bcmath --enable-calendar '\
38
+ '--enable-cli --enable-dba=shared --enable-fastcgi --enable-force-redirect '\
39
+ '--enable-force-cgi-redirect --enable-inline-optimization '\
40
+ '--with-config-file-path=$MY_PHP '\
41
+ '--with-iconv-dir=/Programs/Libiconv/Current/ '\
42
+ '--with-gdbm --with-gmp --without-gd '\
43
+ '--without-iconv --without-sqlite --disable-debug'
44
+ ]
45
+
46
+ array_test_this_input.each {|entry|
47
+ e ' '+
48
+ tomato(entry.ljust(30))+
49
+ lightblue(' → ')+
50
+ steelblue(
51
+ ConvertGlobalEnv[entry]
52
+ )
53
+ }
32
54
  e
55
+ cliner
56
+ e royalblue('Next we will test the rcfiles gem in combination with ConvertGlobalEnv.')
57
+ _ = ConvertGlobalEnv.new
58
+ e gold(_.hash?.keys.size)
59
+ _.load_values_from_the_rcfiles_gem
60
+ e gold(_.hash?.keys.size)
61
+ e royalblue('The two values displayed above ^^^ should be different.')
62
+ cliner
metadata CHANGED
@@ -1,39 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convert_global_env
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.23
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert A. Heiler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-15 00:00:00.000000000 Z
11
+ date: 2022-05-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2+
14
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.
15
+ This module translates a string like $FOO/bar into the corresponding
16
+ ENV variable, i.e. ENV['FOO']+'/bar'. This gem has no external
17
+ dependencies.
18
18
 
19
19
  email: shevy@inbox.lt
20
20
  executables: []
21
21
  extensions: []
22
- extra_rdoc_files:
23
- - USAGE.md
22
+ extra_rdoc_files: []
24
23
  files:
25
- - USAGE.md
24
+ - README.md
25
+ - bin/convert_global_env
26
26
  - convert_global_env.gemspec
27
+ - doc/README.gen
27
28
  - lib/convert_global_env.rb
28
29
  - 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
30
+ - lib/convert_global_env/class/convert_global_env.rb
31
+ - lib/convert_global_env/constants/constants.rb
32
+ - lib/convert_global_env/images/logo/CONVERT_GLOBAL_ENV_LOGO.png
33
+ - lib/convert_global_env/toplevel_methods/toplevel_methods.rb
32
34
  - lib/convert_global_env/version/version.rb
35
+ - test/testing_cgi_environment.cgi
33
36
  - test/testing_convert_global_env.rb
34
37
  homepage: https://rubygems.org/gems/convert_global_env
35
38
  licenses:
36
- - GPL-2.0
39
+ - MIT
37
40
  metadata: {}
38
41
  post_install_message:
39
42
  rdoc_options: []
@@ -48,12 +51,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
51
  requirements:
49
52
  - - ">="
50
53
  - !ruby/object:Gem::Version
51
- version: 3.2.24
54
+ version: 3.3.13
52
55
  requirements: []
53
- rubygems_version: 3.2.24
56
+ rubygems_version: 3.3.13
54
57
  signing_key:
55
58
  specification_version: 4
56
59
  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.
60
+ variable, i.e. ENV['FOO']+'/bar'. This gem has no external dependencies.
58
61
  test_files: []
59
62
  ...
data/USAGE.md DELETED
@@ -1,15 +0,0 @@
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']
@@ -1,50 +0,0 @@
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
@@ -1,99 +0,0 @@
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