ykxutils 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.rubocop_todo.yml +125 -51
  4. data/Gemfile +13 -9
  5. data/Gemfile.lock +18 -6
  6. data/Rakefile +25 -8
  7. data/lib/ykxutils/erubyx.rb +52 -0
  8. data/lib/ykxutils/gridlist.rb +49 -0
  9. data/lib/ykxutils/nginxconfig.rb +40 -0
  10. data/lib/ykxutils/nginxconfigfiles.rb +33 -0
  11. data/lib/ykxutils/pstorex.rb +1 -1
  12. data/lib/ykxutils/version.rb +1 -1
  13. data/lib/ykxutils/yamlx.rb +31 -34
  14. data/lib/ykxutils.rb +4 -0
  15. data/test_data/4servers.erb +7 -0
  16. data/test_data/v103-3-189-127/4servers.erb +0 -0
  17. data/test_data/v103-3-189-127/a.northern-cross.net/base.yml +28 -0
  18. data/test_data/v103-3-189-127/a.northern-cross.net/value_host.yml +1 -0
  19. data/test_data/v103-3-189-127/b.northern-cross.net/base.yml +28 -0
  20. data/test_data/v103-3-189-127/b.northern-cross.net/value_host.yml +1 -0
  21. data/test_data/v103-3-189-127/c.northern-cross.net/base.yml +28 -0
  22. data/test_data/v103-3-189-127/c.northern-cross.net/value_host.yml +1 -0
  23. data/test_data/v103-3-189-127/d.northern-cross.info/base.yml +28 -0
  24. data/test_data/v103-3-189-127/d.northern-cross.info/value_host.yml +1 -0
  25. data/test_data/v103-3-189-127/d.northern-cross.net/base.yml +28 -0
  26. data/test_data/v103-3-189-127/d.northern-cross.net/value_host.yml +1 -0
  27. data/test_data/v103-3-189-127/e.northern-cross.info/base.yml +28 -0
  28. data/test_data/v103-3-189-127/e.northern-cross.info/value_host.yml +1 -0
  29. data/test_data/v103-3-189-127/e.northern-cross.net/base.yml +28 -0
  30. data/test_data/v103-3-189-127/e.northern-cross.net/value_host.yml +1 -0
  31. data/test_data/v103-3-189-127/f.northern-cross.info/base.yml +28 -0
  32. data/test_data/v103-3-189-127/f.northern-cross.info/value_host.yml +1 -0
  33. data/test_data/v103-3-189-127/f.northern-cross.net/base.yml +28 -0
  34. data/test_data/v103-3-189-127/f.northern-cross.net/value_host.yml +1 -0
  35. data/test_data/v103-3-189-127/t_server_1.erb +7 -0
  36. data/test_data/v103-3-189-127/template.erb +21 -0
  37. data/test_data/v103-3-189-127/template_ssl.erb +22 -0
  38. data/test_data/v103-3-189-127/template_ssl_www.erb +12 -0
  39. data/test_data/v103-3-189-127/template_www.erb +24 -0
  40. data/test_data/v103-3-189-127/value.yml +3 -0
  41. data/test_data/v103-3-189-127/value_ssl.yml +5 -0
  42. data/ykxutils.gemspec +33 -26
  43. metadata +86 -17
  44. data/.github/workflows/main.yml +0 -16
  45. data/.gitignore +0 -14
  46. data/bin/console +0 -15
  47. data/bin/setup +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a605f435a082619d142a5640b1652656afa839d8229d66a5c4fa56ca9eed9670
4
- data.tar.gz: e84dd667abfd14872203fbecfb2e26bb9241b1ab63ef5eceaa55ea13d37c2f73
3
+ metadata.gz: fb57978cd24ccbb824287f130d77a3c38a6703e0341914b32221adf60786bb73
4
+ data.tar.gz: 92fd92f8550542480f7f44e11870d0a18edc3c7412311d0511bd0c9e554eacbd
5
5
  SHA512:
6
- metadata.gz: cef69aebdfdeeef0dbb4197a8acef30ff28ed833e323f7666ec4cf66efc18ff4d48c9aa274ab31cd39d3d5b53edc41a25407e97c8b1e8bd7daeef6c79a8c2622
7
- data.tar.gz: 69efe970810d2fba038322e72b941cb232c672e8cfdd0a570b637b87f1a204702798fc8be34a606d8ec4840e4b8bd0fb0ccf3f89929c7be4726951e84a89f1d0
6
+ metadata.gz: 594acd0dd1516dfad347315770af817a49df02e09bbee5b3b78f6dae768a6272f450a160318a708e5e3d39b6070be5128bf2d327045da9c516bbe3e891b45e94
7
+ data.tar.gz: 1909511a5120c6a9564f74db65f45d602277df8ee594010f3ea6f7d2da2f7c3dab22bf2aec8739c29369fe75bbee547e6f10ee0171d0ee4b31af76a0940d9e99
data/.rubocop.yml CHANGED
@@ -5,7 +5,7 @@ require:
5
5
  inherit_from: .rubocop_todo.yml
6
6
 
7
7
  AllCops:
8
- TargetRubyVersion: 2.6
8
+ TargetRubyVersion: 2.7
9
9
  NewCops: enable
10
10
 
11
11
  Style/StringLiterals:
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-09-14 22:49:41 UTC using RuboCop version 1.36.0.
3
+ # on 2022-10-11 11:06:24 UTC using RuboCop version 1.36.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -8,98 +8,172 @@
8
8
 
9
9
  # Offense count: 1
10
10
  # This cop supports safe autocorrection (--autocorrect).
11
- Layout/EmptyLineAfterGuardClause:
11
+ # Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
12
+ # Include: **/*.gemfile, **/Gemfile, **/gems.rb
13
+ Bundler/OrderedGems:
12
14
  Exclude:
13
- #- 'lib/ykxutils/gitcmd.rb'
15
+ # - 'Gemfile'
14
16
 
15
17
  # Offense count: 1
16
18
  # This cop supports safe autocorrection (--autocorrect).
17
- Layout/EmptyLines:
19
+ # Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
20
+ # Include: **/*.gemspec
21
+ Gemspec/OrderedDependencies:
18
22
  Exclude:
19
- #- 'lib/ykxutils/gitcmd.rb'
23
+ # - 'ykxutils.gemspec'
20
24
 
21
25
  # Offense count: 1
22
26
  # This cop supports safe autocorrection (--autocorrect).
23
- # Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment.
24
- Layout/LeadingCommentSpace:
27
+ # Configuration parameters: EnforcedStyle.
28
+ # SupportedStyles: space, no_space
29
+ Layout/SpaceAroundEqualsInParameterDefault:
25
30
  Exclude:
26
- #- 'lib/ykxutils/gitcmd.rb'
31
+ # - 'lib/ykxutils/pstorex.rb'
32
+
33
+ # Offense count: 10
34
+ Lint/UselessAssignment:
35
+ Exclude:
36
+ # - 'lib/ykxutils/yamlx.rb'
27
37
 
28
38
  # Offense count: 1
29
- # This cop supports safe autocorrection (--autocorrect).
30
- # Configuration parameters: .
31
- # SupportedStyles: space, no_space
32
- Layout/SpaceAroundEqualsInParameterDefault:
33
- EnforcedStyle: no_space
39
+ # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes.
40
+ Metrics/AbcSize:
41
+ Max: 19
42
+
43
+ # Offense count: 3
44
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
45
+ Metrics/MethodLength:
46
+ Max: 15
47
+
48
+ # Offense count: 1
49
+ # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
50
+ Metrics/ParameterLists:
51
+ Max: 6
52
+
53
+ # Offense count: 1
54
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
55
+ # AllowedNames: as, at, by, db, id, in, io, ip, of, on, os, pp, to
56
+ Naming/MethodParameterName:
57
+ Exclude:
58
+ - 'lib/ykxutils/nginxconfigfiles.rb'
34
59
 
35
60
  # Offense count: 1
36
61
  # This cop supports safe autocorrection (--autocorrect).
37
- # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
38
- # SupportedStylesForExponentOperator: space, no_space
39
- Layout/SpaceAroundOperators:
62
+ # Configuration parameters: EnforcedStyle.
63
+ # SupportedStyles: be, be_nil
64
+ RSpec/BeNil:
65
+ Exclude:
66
+ - 'spec/ykxutils_spec.rb'
67
+
68
+ # Offense count: 1
69
+ RSpec/BeforeAfterAll:
40
70
  Exclude:
41
- # - 'lib/ykxutils/gitcmd.rb'
71
+ - 'spec/spec_helper.rb'
72
+ - 'spec/rails_helper.rb'
73
+ - 'spec/support/**/*.rb'
74
+ - 'spec/ykxutils_spec.rb'
42
75
 
43
76
  # Offense count: 2
44
- # This cop supports safe autocorrection (--autocorrect).
45
- # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
46
- # SupportedStyles: space, no_space
47
- # SupportedStylesForEmptyBraces: space, no_space
48
- Layout/SpaceBeforeBlockBraces:
77
+ # Configuration parameters: CountAsOne.
78
+ RSpec/ExampleLength:
79
+ Max: 9
80
+
81
+ # Offense count: 1
82
+ # Configuration parameters: AssignmentOnly.
83
+ RSpec/InstanceVariable:
49
84
  Exclude:
50
- # - 'lib/ykxutils/gitcmd.rb'
85
+ - 'spec/ykxutils_spec.rb'
51
86
 
52
- # Offense count: 4
53
- # This cop supports safe autocorrection (--autocorrect).
54
- # Configuration parameters: EnforcedStyle.
55
- # SupportedStyles: space, compact, no_space
56
- Layout/SpaceInsideParens:
87
+ # Offense count: 1
88
+ RSpec/NoExpectationExample:
57
89
  Exclude:
58
- # - 'lib/ykxutils/gitcmd.rb'
90
+ - 'spec/ykxutils_spec.rb'
59
91
 
60
92
  # Offense count: 1
61
93
  # This cop supports safe autocorrection (--autocorrect).
62
94
  # Configuration parameters: EnforcedStyle.
63
- # SupportedStyles: final_newline, final_blank_line
64
- Layout/TrailingEmptyLines:
95
+ # SupportedStyles: not_to, to_not
96
+ RSpec/NotToNot:
65
97
  Exclude:
66
- # - 'lib/ykxutils/gitcmd.rb'
98
+ - 'spec/ykxutils_spec.rb'
67
99
 
68
- # Offense count: 1
100
+ # Offense count: 8
69
101
  # This cop supports safe autocorrection (--autocorrect).
70
- Lint/ScriptPermission:
102
+ # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
103
+ # SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
104
+ # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
105
+ # FunctionalMethods: let, let!, subject, watch
106
+ # AllowedMethods: lambda, proc, it
107
+ Style/BlockDelimiters:
71
108
  Exclude:
72
- - 'bin/console'
109
+ - 'lib/ykxutils/erubyx.rb'
110
+ - 'lib/ykxutils/gridlist.rb'
111
+ - 'lib/ykxutils/nginxconfig.rb'
112
+ - 'lib/ykxutils/nginxconfigfiles.rb'
113
+ - 'spec/ykxutils_spec.rb'
73
114
 
74
- # Offense count: 9
75
- Lint/UselessAssignment:
115
+ # Offense count: 5
116
+ # This cop supports safe autocorrection (--autocorrect).
117
+ Style/ColonMethodCall:
76
118
  Exclude:
77
- #- 'lib/ykxutils/gitcmd.rb'
78
- #- 'lib/ykxutils/yamlx.rb'
119
+ - 'lib/ykxutils/gridlist.rb'
120
+ - 'lib/ykxutils/nginxconfig.rb'
121
+ - 'spec/ykxutils_spec.rb'
79
122
 
80
123
  # Offense count: 1
81
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
82
- Metrics/MethodLength:
83
- Max: 17
124
+ # This cop supports safe autocorrection (--autocorrect).
125
+ Style/EachWithObject:
126
+ Exclude:
127
+ - 'spec/ykxutils_spec.rb'
128
+
129
+ # Offense count: 3
130
+ # This cop supports safe autocorrection (--autocorrect).
131
+ # Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
132
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
133
+ # SupportedShorthandSyntax: always, never, either, consistent
134
+ Style/HashSyntax:
135
+ Exclude:
136
+ - 'lib/ykxutils/gridlist.rb'
137
+
138
+ # Offense count: 2
139
+ # This cop supports safe autocorrection (--autocorrect).
140
+ Style/IfUnlessModifier:
141
+ Exclude:
142
+ - 'lib/ykxutils/erubyx.rb'
143
+ - 'lib/ykxutils/gridlist.rb'
84
144
 
85
145
  # Offense count: 1
86
146
  # This cop supports unsafe autocorrection (--autocorrect-all).
87
- # Configuration parameters: InverseMethods, InverseBlocks.
88
- Style/InverseMethods:
147
+ # Configuration parameters: EnforcedStyle.
148
+ # SupportedStyles: literals, strict
149
+ Style/MutableConstant:
89
150
  Exclude:
90
- #- 'lib/ykxutils/gitcmd.rb'
151
+ - 'lib/ykxutils/gridlist.rb'
91
152
 
92
153
  # Offense count: 2
93
- # This cop supports unsafe autocorrection (--autocorrect-all).
94
- # Configuration parameters: Methods.
95
- Style/RedundantArgument:
154
+ # This cop supports safe autocorrection (--autocorrect).
155
+ # Configuration parameters: EnforcedStyle, MinBodyLength.
156
+ # SupportedStyles: skip_modifier_ifs, always
157
+ Style/Next:
158
+ Exclude:
159
+ - 'lib/ykxutils/nginxconfig.rb'
160
+ - 'lib/ykxutils/nginxconfigfiles.rb'
161
+
162
+ # Offense count: 1
163
+ # This cop supports safe autocorrection (--autocorrect).
164
+ # Configuration parameters: PreferredDelimiters.
165
+ Style/PercentLiteralDelimiters:
96
166
  Exclude:
97
- # - 'lib/ykxutils/gitcmd.rb'
167
+ - 'lib/ykxutils/gridlist.rb'
98
168
 
99
- # Offense count: 4
169
+ # Offense count: 45
100
170
  # This cop supports safe autocorrection (--autocorrect).
101
171
  # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
102
172
  # SupportedStyles: single_quotes, double_quotes
103
173
  Style/StringLiterals:
104
174
  Exclude:
105
- # - 'lib/ykxutils/gitcmd.rb'
175
+ - 'Gemfile'
176
+ - 'lib/ykxutils/erubyx.rb'
177
+ - 'lib/ykxutils/gridlist.rb'
178
+ - 'lib/ykxutils/nginxconfigfiles.rb'
179
+ - 'ykxutils.gemspec'
data/Gemfile CHANGED
@@ -1,18 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in ykxutils.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
9
-
10
- gem "rspec", "~> 3.0"
11
-
12
- gem "rubocop", "~> 1.7"
13
- gem "rubocop-rake", require: false
14
- gem "rubocop-rspec", require: false
8
+ gem 'bundler'
9
+ gem 'erubi'
10
+ gem 'rake', '~> 13.0'
11
+ gem 'tilt'
15
12
 
16
13
  group :development do
17
- gem "yard"
14
+ gem 'yard'
15
+ end
16
+
17
+ group :test do
18
+ gem 'rspec', '~> 3.0'
19
+ gem 'rubocop'
20
+ gem 'rubocop-rake', require: false
21
+ gem 'rubocop-rspec', require: false
18
22
  end
data/Gemfile.lock CHANGED
@@ -1,20 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ykxutils (0.1.6)
4
+ ykxutils (0.1.8)
5
+ bundler
6
+ erubi
7
+ rake (~> 13.0)
8
+ tilt
5
9
 
6
10
  GEM
7
11
  remote: https://rubygems.org/
8
12
  specs:
9
13
  ast (2.4.2)
10
14
  diff-lcs (1.5.0)
15
+ erubi (1.11.0)
11
16
  json (2.6.2)
12
17
  parallel (1.22.1)
13
18
  parser (3.1.2.1)
14
19
  ast (~> 2.4.1)
15
20
  rainbow (3.1.1)
16
21
  rake (13.0.6)
17
- regexp_parser (2.5.0)
22
+ regexp_parser (2.6.0)
18
23
  rexml (3.2.5)
19
24
  rspec (3.11.0)
20
25
  rspec-core (~> 3.11.0)
@@ -41,12 +46,16 @@ GEM
41
46
  unicode-display_width (>= 1.4.0, < 3.0)
42
47
  rubocop-ast (1.21.0)
43
48
  parser (>= 3.1.1.0)
49
+ rubocop-performance (1.15.0)
50
+ rubocop (>= 1.7.0, < 2.0)
51
+ rubocop-ast (>= 0.4.0)
44
52
  rubocop-rake (0.6.0)
45
53
  rubocop (~> 1.0)
46
- rubocop-rspec (2.13.1)
54
+ rubocop-rspec (2.13.2)
47
55
  rubocop (~> 1.33)
48
56
  ruby-progressbar (1.11.0)
49
- unicode-display_width (2.2.0)
57
+ tilt (2.0.11)
58
+ unicode-display_width (2.3.0)
50
59
  webrick (1.7.0)
51
60
  yard (0.9.28)
52
61
  webrick (~> 1.7.0)
@@ -56,13 +65,16 @@ PLATFORMS
56
65
 
57
66
  DEPENDENCIES
58
67
  bundler
68
+ erubi
59
69
  rake (~> 13.0)
60
70
  rspec (~> 3.0)
61
- rubocop (~> 1.7)
71
+ rubocop
72
+ rubocop-performance
62
73
  rubocop-rake
63
74
  rubocop-rspec
75
+ tilt
64
76
  yard
65
77
  ykxutils!
66
78
 
67
79
  BUNDLED WITH
68
- 2.3.17
80
+ 2.3.22
data/Rakefile CHANGED
@@ -1,12 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
4
 
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
5
+ begin
6
+ require "rspec/core/rake_task"
7
+ rescue LoadError => e
8
+ puts e.message
9
+ end
10
+ begin
11
+ RSpec::Core::RakeTask.new(:spec)
12
+ rescue NameError, LoadError => e
13
+ puts e.message
14
+ end
15
+ begin
16
+ require "rubocop/rake_task"
17
+ rescue LoadError => e
18
+ puts e.message
19
+ end
20
+ begin
21
+ RuboCop::RakeTask.new
22
+ rescue NameError, LoadError => e
23
+ puts e.message
24
+ end
25
+ begin
26
+ task default: %i[spec rubocop]
27
+ rescue LoadError => e
28
+ puts e.message
29
+ end
@@ -0,0 +1,52 @@
1
+ require 'tilt'
2
+ require 'yaml'
3
+
4
+ module Ykxutils
5
+ module Erubyx
6
+ module_function
7
+
8
+ def erubi_render(template_hash, scope, value_hash = {})
9
+ unless template_hash[:OBJ]
10
+ template_hash[:OBJ] = Tilt::ErubiTemplate.new { template_hash[:TEMPLATE] }
11
+ end
12
+ template_hash[:OBJ].render(scope, value_hash)
13
+ end
14
+
15
+ ##
16
+ # `erubi_render_with_file` takes a template file path, a scope, and a value file path, reads the
17
+ # template file, loads the value file, and then calls `erubi_render` with the template hash, scope,
18
+ # and value hash
19
+ #
20
+ # Args:
21
+ # template_file_path: The path to the template file.
22
+ # scope: the scope of the template. This is the name of the directory that the template is in.
23
+ # value_file_path: The path to the YAML file that contains the values to be used in the template.
24
+ def erubi_render_with_file(template_file_path, scope, value_file_path_array)
25
+ template_text = File.read(template_file_path)
26
+ template_hash = { TEMPLATE: template_text,
27
+ OBJ: nil }
28
+ value_hash = value_file_path_array.reduce({}) { |hash, path|
29
+ # p path
30
+ hash0 = YAML.load_file(path)
31
+ # p hash0
32
+ hash = hash.merge(hash0)
33
+ # p hash
34
+ hash
35
+ }
36
+ # puts value_hash
37
+ erubi_render(template_hash, scope, value_hash)
38
+ end
39
+
40
+ def erubi_render_with_template_file(template_file_path, scope, value_hash = {})
41
+ template_text = File.read(template_file_path)
42
+ template_hash = make_template_hash(template_text)
43
+ # puts value_hash
44
+ erubi_render(template_hash, scope, value_hash)
45
+ end
46
+
47
+ def make_template_hash(text)
48
+ { TEMPLATE: text,
49
+ OBJ: nil }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,49 @@
1
+ require 'ykxutils/erubyx'
2
+
3
+ module Ykxutils
4
+ module Gridlist
5
+ TAMPLETES = { :GRID_DEF =>
6
+ { :TEMPLATE => %!
7
+ .g-<%= row %>-<%= colum %> {
8
+ grid-row-start: <%= row %>;
9
+ grid-row-end: ,<%= row + 1 %>;
10
+ grid-column-start: <%= colum %>;
11
+ grid-column-end: <%= colum + 1 %>;
12
+ }
13
+ !, :OBJ => nil } }
14
+
15
+ module_function
16
+
17
+ def make_one_grid(hash, row, colum)
18
+ unless hash[:OBJ]
19
+ hash[:OBJ] = Tilt::ErubiTemplate.new { hash[:TEMPLATE] }
20
+ end
21
+ hash[:OBJ].render(Object.new, { row: row, colum: colum })
22
+ end
23
+
24
+ def make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
25
+ (min_row..max_row).map { |row|
26
+ (min_colum..max_colum).map { |colum|
27
+ # puts "#{row} #{colum}"
28
+ value_hash = { row: row, colum: colum }
29
+ # make_one_grid(template_hash, value_hash)
30
+ # p template_hash
31
+ # p value_hash
32
+ Ykxutils::Erubyx::erubi_render(template_hash, scope, value_hash)
33
+ }
34
+ }
35
+ end
36
+
37
+ def make_grid_list(min_row, max_row, min_colum, max_colum)
38
+ template_hash = TAMPLETES[:GRID_DEF]
39
+ scope = nil
40
+ make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
41
+ end
42
+
43
+ def make_grid_list_x(min_row, max_row, min_colum, max_colum)
44
+ template_hash = TAMPLETES[:GRID_DEF]
45
+ scope = nil
46
+ make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,40 @@
1
+ module Ykxutils
2
+ class Nginxconfig
3
+ def initialize(yaml_path)
4
+ # p "yaml_path=#{yaml_path}"
5
+ yaml_pn = Pathname.new(yaml_path).cleanpath
6
+ @virtual_domain_dir_pn = yaml_pn.parent
7
+ @server_dir_pn = @virtual_domain_dir_pn.parent
8
+ @common_dir_pn = @server_dir_pn.parent
9
+ @hash = YAML.load_file(yaml_pn)
10
+ # p @hash
11
+ @root = @hash["_root"]
12
+ # p @root
13
+ root_template_0_pn = Pathname.new(@root["template"]).cleanpath
14
+ @root_template_pn = @common_dir_pn + root_template_0_pn
15
+ # puts "@root_template_pn=#{@root_template_pn}"
16
+ end
17
+
18
+ def extract(scope)
19
+ hashx = {}
20
+ @hash.each do |k, v|
21
+ if k !~ /^_/
22
+ # puts k
23
+ # puts v
24
+ pn = Pathname.new(v["template"]).cleanpath
25
+ # Pathname.new(v).cleanpath
26
+ template_pn = @server_dir_pn + pn
27
+ # puts(template_pn)
28
+ value_file_path_array = v["value"].map { |x|
29
+ @virtual_domain_dir_pn + Pathname.new(x).cleanpath
30
+ }
31
+ hashx[k] = Ykxutils::Erubyx::erubi_render_with_file(template_pn, scope, value_file_path_array)
32
+ end
33
+ end
34
+ template = File.read(@root_template_pn)
35
+ template_hash = { TEMPLATE: template,
36
+ OBJ: nil }
37
+ Ykxutils::Erubyx::erubi_render(template_hash, scope, hashx)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ require 'find'
2
+ require_relative 'nginxconfig'
3
+
4
+ module Ykxutils
5
+ class Nginxconfigfiles
6
+ def get_file_list(start_dir, re)
7
+ @file_list = []
8
+
9
+ Find.find(start_dir) { |x|
10
+ if x =~ re
11
+ # puts x
12
+ @file_list << x
13
+ Find.prune
14
+ end
15
+ }
16
+ @file_list
17
+ end
18
+
19
+ def output(file_list)
20
+ file_list.map { |fname|
21
+ parent_dir_pn = Pathname.new(fname).cleanpath.parent
22
+ vdomain = parent_dir_pn.basename
23
+ output_fname = "#{vdomain}.conf"
24
+ cli = ::Ykxutils::Nginxconfig.new(fname)
25
+ scope = nil
26
+ File.open(output_fname, "w") { |f|
27
+ x = cli.extract(scope)
28
+ f.write(x)
29
+ }
30
+ }
31
+ end
32
+ end
33
+ end
@@ -3,7 +3,7 @@ require "fileutils"
3
3
 
4
4
  module Ykxutils
5
5
  class Pstorex
6
- def initialize(store_dir, dump_file="pstore.dump")
6
+ def initialize(store_dir, dump_file = "pstore.dump")
7
7
  FileUtils.mkdir_p(store_dir)
8
8
  @store_db = PStore.new(Pathname.new(store_dir).join(dump_file))
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ykxutils
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.8"
5
5
  end
@@ -3,46 +3,43 @@ require "yaml"
3
3
  module Ykxutils
4
4
  module_function
5
5
 
6
- def yaml_load_file_compati(yaml_file_path)
7
- setting = {}
8
- valid = false
6
+ def yaml_load_file_aliases(yaml_file_path, use_aliases: true)
9
7
  begin
10
- setting = YAML.load_file(yaml_file_path, aliases: true)
11
- valid = true
8
+ use_aliases ? YAML.load_file(yaml_file_path, aliases: true) : YAML.load_file(yaml_file_path)
9
+ value = 0
12
10
  rescue ArgumentError
13
- # p "yaml_load_file_compat 1"
14
- # p ex.class
15
- # p ex.inspect
16
- # p ex.message
17
- # p ex.backtrace
18
- # exit#
11
+ # puts e.message
12
+ value = 1
19
13
  rescue StandardError
20
- # p "yaml_load_file_compat 1-2"
21
- # p ex.class
22
- # p ex.inspect
23
- # p ex.message
24
- # p ex.backtrace
14
+ # puts e.message
15
+ value = 2
25
16
  end
17
+ value
18
+ end
19
+
20
+ def yaml_load_file_compati(yaml_file_path)
21
+ setting = yaml_load_file_aliases(yaml_file_path, use_aliases: true)
22
+ setting = yaml_load_file_aliases(yaml_file_path, use_aliases: false) if setting.nil?
23
+ setting
24
+ end
26
25
 
27
- if valid != true
28
- begin
29
- setting = YAML.load_file(yaml_file_path)
30
- # valid = true
31
- rescue ArgumentError
32
- # p "yaml_load_file_compat 2"
33
- # p ex.class
34
- # p ex.inspect
35
- # p ex.message
36
- # p ex.backtrace
37
- #
38
- rescue StandardError
39
- # p "yaml_load_file_compat 2-2"
40
- # p ex.class
41
- # p ex.inspect
42
- # p ex.message
43
- # p ex.backtrace
44
- end
26
+ def yaml_load_aliases(content, use_aliases: true)
27
+ begin
28
+ use_aliases ? YAML.safe_load(content, aliases: true) : YAML.safe_load(content)
29
+ value = 0
30
+ rescue ArgumentError
31
+ # puts e.message
32
+ value = 1
33
+ rescue StandardError
34
+ # puts e.message
35
+ value = 2
45
36
  end
37
+ value
38
+ end
39
+
40
+ def yaml_load_compati(content)
41
+ setting = yaml_load_aliases(content, use_aliases: true)
42
+ setting = yaml_load_aliases(content, use_aliases: false) if setting.nil?
46
43
  setting
47
44
  end
48
45
  end
data/lib/ykxutils.rb CHANGED
@@ -2,8 +2,12 @@
2
2
 
3
3
  require_relative "ykxutils/version"
4
4
  require_relative "ykxutils/yamlx"
5
+ require_relative "ykxutils/erubyx"
5
6
  require_relative "ykxutils/pstorex"
6
7
  require_relative "ykxutils/gitcmd"
8
+ require_relative "ykxutils/nginxconfig"
9
+ require_relative "ykxutils/nginxconfigfiles"
10
+ require_relative "ykxutils/gridlist"
7
11
 
8
12
  module Ykxutils
9
13
  class Error < StandardError; end