ykutils 0.1.6 → 0.1.8

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.
data/SECURITY.md ADDED
@@ -0,0 +1,21 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 5.1.x | :white_check_mark: |
11
+ | 5.0.x | :x: |
12
+ | 4.0.x | :white_check_mark: |
13
+ | < 4.0 | :x: |
14
+
15
+ ## Reporting a Vulnerability
16
+
17
+ Use this section to tell people how to report a vulnerability.
18
+
19
+ Tell them where to go, how often they can expect to get an update on a
20
+ reported vulnerability, what to expect if the vulnerability is accepted or
21
+ declined, etc.
data/bin/console CHANGED
File without changes
data/bin/erubix CHANGED
@@ -13,5 +13,5 @@ while ARGV.size > ind
13
13
  end
14
14
 
15
15
  scope = nil
16
- content = Ykutils::Erubyx::erubi_render_with_file(template_file_path, scope, value_file_path_array)
16
+ content = Ykutils::Erubyx.erubi_render_with_file(template_file_path, scope, value_file_path_array)
17
17
  puts content
data/bin/erubix2 CHANGED
@@ -3,8 +3,8 @@
3
3
 
4
4
  require "bundler/setup"
5
5
  require "ykutils"
6
- require 'yaml'
7
- require 'find'
6
+ require "yaml"
7
+ require "find"
8
8
 
9
9
  ncf = Ykutils::Nginxconfigfiles.new
10
10
  re = /base.yml$/
data/bin/makegrid CHANGED
@@ -20,4 +20,4 @@ min_row = ARGV[0].to_i
20
20
  max_row = ARGV[1].to_i
21
21
  min_colum = ARGV[2].to_i
22
22
  max_colum = ARGV[3].to_i
23
- puts Ykutils::Gridlist::make_grid_list_x(min_row, max_row, min_colum, max_colum)
23
+ puts Ykutils::Gridlist.make_grid_list_x(min_row, max_row, min_colum, max_colum)
@@ -1,101 +1,103 @@
1
- require "pp"
2
-
3
1
  module Ykutils
4
2
  module DebugUtils
5
3
  class DebugMes
6
- def self.init(debug = false)
7
- @@debug = debug
8
- @@buf = []
4
+ @debug = false
5
+ @warn = false
6
+ @buf = []
7
+
8
+ def self.init(debug: false)
9
+ @debug = debug
10
+ @buf = []
11
+ end
12
+
13
+ class << self
14
+ attr_accessor :debug
9
15
  end
10
16
 
11
- def self.set_debug(debug)
12
- @@debug = debug
17
+ class << self
18
+ attr_accessor :warn
13
19
  end
14
20
 
15
21
  def self.puts_x(mes)
16
- @@buf ||= []
17
- @@buf << mes
18
- # puts "#{@@buf.size} |#{mes}"
22
+ @buf << mes
19
23
  end
20
24
 
21
25
  def self.get
22
- @@buf
23
- # DebugMes.clear
26
+ @buf
24
27
  end
25
28
 
26
29
  def self.clear
27
- @@buf ||= []
28
- @@buf.clear
30
+ @buf.clear
29
31
  end
30
32
  end
31
33
 
32
34
  def clear_d
33
- DebugMes.clear
35
+ Ykutils::DebugUtils::DebugMes..clear
34
36
  end
35
37
 
36
38
  def puts_d(mes)
37
- DebugMes.puts_x(mes)
39
+ Ykutils::DebugUtils::DebugMes..puts_x(mes)
38
40
  # puts mes
39
41
  end
40
42
 
41
- def get_d
42
- DebugMes.get
43
+ def d
44
+ self.class.get
43
45
  end
44
46
 
45
47
  def puts_current_method
46
- d_puts (caller(1)[0].split)[-1]
48
+ d_puts caller(1)[0].split[-1]
47
49
  end
48
50
 
49
- def error_exit(n)
50
- puts "error(#{n})"
51
+ def error_exit(num)
52
+ puts "error(#{num})"
51
53
  pp caller(0)
52
54
  exit(n)
53
55
  end
54
56
 
55
57
  def debug_utils_init
56
- set_debug(false)
58
+ debug(false)
57
59
  set_warn(0)
58
60
 
59
- DebugMes.init(false)
61
+ Ykutils::DebugUtils::DebugMes.init(false)
60
62
  end
61
63
 
62
- def set_debug(val)
63
- @debugutils = val
64
- DebugMes.set_debug(val)
65
- end
64
+ # def debug(val)
65
+ # # self.class.set_debug(val)
66
+ # Ykutils::DebugUtils::DebugMes.debug(val)
67
+ # end
66
68
 
67
- def get_debug
68
- @debugutils
69
- end
69
+ # def debug
70
+ # Ykutils::DebugUtils::DebugMes.get_debug
71
+ # end
70
72
 
71
- def set_warn(val)
72
- @warn = val
73
- end
73
+ # def warn(val)
74
+ # Ykutils::DebugUtils::DebugMes.set_warn(val)
75
+ # end
74
76
 
75
- def debug
76
- @debugutils
77
- end
77
+ # def warn
78
+ # Ykutils::DebugUtils::DebugMes..get_warn
79
+ # end
78
80
 
79
81
  def d_exit(num)
80
- exit(num) if @debugutils
82
+ exit(num) if get_debug
81
83
  end
82
84
 
83
85
  def d_puts(str)
84
- puts(str) if @debugutils
86
+ puts(str) if get_debug
85
87
  end
86
88
 
87
89
  def w1_puts(str)
88
- set_warn(0) unless @warn
89
- puts(str) if @debugutils or @warn >= 1
90
+ set_warn(0) unless get_warn
91
+ puts(str) if get_debug || (get_warn >= 1)
90
92
  end
91
93
 
92
94
  def w2_puts(str)
93
- set_warn(0) unless @warn
94
- puts(str) if @debugutils or @warn >= 2
95
+ set_warn(0) unless get_warn
96
+ puts(str) if get_debug || (get_warn >= 2)
95
97
  end
96
98
 
97
99
  def d_caller(_num)
98
- pp caller(0) if @debugutils
100
+ pp caller(0) if get_debug
99
101
  end
100
102
 
101
103
  def puts_no_empty(mes)
@@ -103,20 +105,20 @@ module Ykutils
103
105
  end
104
106
 
105
107
  def d_puts_no_empty(mes)
106
- puts mes if mes != "" and @debugutils
108
+ puts mes if (mes != "") && get_debug
107
109
  end
108
110
 
109
- def d_p(it)
110
- p it if @debugutils
111
+ def d_p(mes)
112
+ p mes if get_debug
111
113
  end
112
114
 
113
- def d_pp(it)
114
- if @debugutils
115
- pp "@debugutils=#{@debugutils}"
115
+ def d_pp(mes)
116
+ if debug
117
+ pp "debug=#{debug}"
116
118
  pp caller(0)
117
119
  exit
118
120
  end
119
- pp it if @debugutils
121
+ pp mes if get_debug
120
122
  end
121
123
  end
122
124
  end
@@ -1,14 +1,12 @@
1
- require 'tilt'
2
- require 'yaml'
1
+ require "tilt"
2
+ require "yaml"
3
3
 
4
4
  module Ykutils
5
5
  module Erubyx
6
6
  module_function
7
7
 
8
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
9
+ template_hash[:OBJ] = Tilt::ErubiTemplate.new { template_hash[:TEMPLATE] } unless template_hash[:OBJ]
12
10
  template_hash[:OBJ].render(scope, value_hash)
13
11
  end
14
12
 
@@ -25,14 +23,14 @@ module Ykutils
25
23
  template_text = File.read(template_file_path)
26
24
  template_hash = { TEMPLATE: template_text,
27
25
  OBJ: nil }
28
- value_hash = value_file_path_array.reduce({}) { |hash, path|
26
+ value_hash = value_file_path_array.reduce({}) do |hash, path|
29
27
  # p path
30
28
  hash0 = YAML.load_file(path)
31
29
  # p hash0
32
30
  hash = hash.merge(hash0)
33
31
  # p hash
34
32
  hash
35
- }
33
+ end
36
34
  # puts value_hash
37
35
  erubi_render(template_hash, scope, value_hash)
38
36
  end
@@ -84,7 +84,7 @@ module Ykutils
84
84
 
85
85
  def valid_readable_fname?(fname)
86
86
  ret = false
87
- ret = true if normal_string?(fname) and File.file?(fname) and File.readable?(fname)
87
+ ret = true if normal_string?(fname) && File.file?(fname) && File.readable?(fname)
88
88
  ret
89
89
  end
90
90
 
@@ -130,7 +130,7 @@ module Ykutils
130
130
  ret = true if File.writable?(fname)
131
131
  else
132
132
  unless File.directory?(fname)
133
- dir, filename = File.split(fname)
133
+ dir, = File.split(fname)
134
134
  ret = valid_writable_directory?(dir)
135
135
  end
136
136
  end
@@ -164,33 +164,33 @@ module Ykutils
164
164
  pp e.traceback
165
165
  @valid = false
166
166
  end
167
- if @valid
168
- content = ary.join("\n")
169
- begin
170
- output_file.write(content)
171
- rescue StandardError => e
172
- pp e
173
- pp e.traceback
174
- @valid = false
175
- end
167
+ return unless @valid
168
+
169
+ content = ary.join("\n")
170
+ begin
171
+ output_file.write(content)
172
+ rescue StandardError => e
173
+ pp e
174
+ pp e.traceback
175
+ @valid = false
176
176
  end
177
177
  end
178
178
 
179
- def rewrite_file(from_path_1, from_path_2, to_path_1, to_path_2)
179
+ def rewrite_file(from_path1, from_path2, to_path1, to_path2)
180
180
  d_p("rewrite_file")
181
- d_p("from_path_1=#{from_path_1}")
182
- d_p("from_path_2=#{from_path_2}")
183
- d_p("to_path_1=#{to_path_1}")
184
- d_p("to_path_2=#{to_path_2}")
181
+ d_p("from_path_1=#{from_path1}")
182
+ d_p("from_path_2=#{from_path2}")
183
+ d_p("to_path_1=#{to_path1}")
184
+ d_p("to_path_2=#{to_path2}")
185
185
 
186
- mes = prepare_file_copy(from_path_1, from_path_2, to_path_1, to_path_2)
186
+ mes = prepare_file_copy(from_path1, from_path2, to_path1, to_path2)
187
187
 
188
188
  puts_no_empty(mes)
189
189
 
190
190
  return false unless @valid
191
191
 
192
- from_path = File.join(from_path_1, from_path_2)
193
- to_path = File.join(to_path_1, to_path_2)
192
+ from_path = File.join(from_path1, from_path2)
193
+ to_path = File.join(to_path1, to_path2)
194
194
  ary = []
195
195
  begin
196
196
  File.open(from_path, "r") do |file|
@@ -218,66 +218,66 @@ module Ykutils
218
218
  end
219
219
  end
220
220
 
221
- def prepare_file_copy(from_path_1, from_path_2, to_path_1, to_path_2)
221
+ def prepare_file_copy(from_path1, from_path2, to_path1, to_path2)
222
222
  mes = ""
223
223
 
224
224
  d_p("prepare_file_copy")
225
- d_p("from_path_1=#{from_path_1}")
226
- d_p("from_path_2=#{from_path_2}")
227
- d_p("to_path_1=#{to_path_1}")
228
- d_p("to_path_2=#{to_path_2}")
229
-
230
- if prepare_source_dir(from_path_1, from_path_2)
231
- unless prepare_dest_dir(to_path_1, to_path_2)
232
- mes = "Can't write #{to_path_1}/#{to_path_1}"
225
+ d_p("from_path_1=#{from_path1}")
226
+ d_p("from_path_2=#{from_path2}")
227
+ d_p("to_path_1=#{to_path1}")
228
+ d_p("to_path_2=#{to_path2}")
229
+
230
+ if prepare_source_dir(from_path1, from_path2)
231
+ unless prepare_dest_dir(to_path1, to_path2)
232
+ mes = "Can't write #{to_path1}/#{to_path1}"
233
233
  d_caller(0)
234
234
  @valid = false
235
235
  end
236
236
  else
237
- mes = "Can't read #{from_path_1}/#{from_path_2}"
237
+ mes = "Can't read #{from_path1}/#{from_path2}"
238
238
  @valid = false
239
239
  end
240
240
 
241
241
  mes
242
242
  end
243
243
 
244
- def prepare_source_dir(from_path_1, from_path_2)
244
+ def prepare_source_dir(from_path1, from_path2)
245
245
  state = false
246
- from_path = File.join(from_path_1, from_path_2)
247
- if valid_readable_directory?(from_path_1)
248
- dirname, filename = File.split(from_path)
246
+ from_path = File.join(from_path1, from_path2)
247
+ if valid_readable_directory?(from_path1)
248
+ dirname, = File.split(from_path)
249
249
  state = true if valid_readable_directory?(dirname) && valid_readable_fname?(from_path)
250
250
  end
251
251
  state
252
252
  end
253
253
 
254
- def prepare_dest_dir(to_path_1, to_path_2)
254
+ def prepare_dest_dir(to_path1, to_path2)
255
255
  state = true
256
- unless valid_writable_directory?(to_path_1)
257
- if File.exist?(to_path_1)
256
+ unless valid_writable_directory?(to_path1)
257
+ if File.exist?(to_path1)
258
258
  d_caller(0)
259
259
  return false
260
260
  end
261
261
 
262
262
  begin
263
- FileUtils.mkdir_p(to_path_1)
263
+ FileUtils.mkdir_p(to_path1)
264
264
  rescue StandardError => e
265
265
  state = false
266
266
  pp e
267
267
  pp e.traceback
268
268
  end
269
269
  end
270
- unless valid_writable_directory?(to_path_1)
270
+ unless valid_writable_directory?(to_path1)
271
271
  d_caller(0)
272
272
  return false
273
273
  end
274
274
 
275
- to_path = File.join(to_path_1, to_path_2)
276
- dirname, filename = File.split(to_path)
275
+ to_path = File.join(to_path1, to_path2)
276
+ dirname, = File.split(to_path)
277
277
  unless File.exist?(dirname)
278
278
  begin
279
279
  FileUtils.mkdir_p(dirname)
280
- rescue StandardError => e
280
+ rescue StandardError
281
281
  state = false
282
282
  pp caller(0)
283
283
  end
@@ -301,22 +301,22 @@ module Ykutils
301
301
  true
302
302
  end
303
303
 
304
- def copy_file(from_path_1, from_path_2, to_path_1, to_path_2)
304
+ def copy_file(from_path1, from_path2, to_path1, to_path2)
305
305
  retry_flag = false
306
306
  begin
307
- from_path = File.join(from_path_1, from_path_2)
308
- to_path = File.join(to_path_1, to_path_2)
307
+ from_path = File.join(from_path1, from_path2)
308
+ to_path = File.join(to_path1, to_path2)
309
309
  FileUtils.cp(from_path, to_path)
310
310
  d_puts("Copy #{from_path} -> #{to_path}")
311
- rescue StandardError => e
312
- retry_flag = prepare_file_copy(from_path_1, from_path_2, to_path_1, to_path_2)
311
+ rescue StandardError
312
+ retry_flag = prepare_file_copy(from_path1, from_path2, to_path1, to_path2)
313
313
  end
314
314
 
315
315
  if retry_flag
316
316
  begin
317
317
  FileUtils.cp(from_path, to_path)
318
318
  d_puts("Copy #{from_path} -> #{to_path}")
319
- rescue StandardError => e
319
+ rescue StandardError
320
320
  @valid = false
321
321
  end
322
322
  end
@@ -331,8 +331,8 @@ module Ykutils
331
331
  d_p(ary)
332
332
  d_p(left)
333
333
  if left
334
- sub_ary = ary[(left + 1)..-1]
335
- ret = true if sub_ary && sub_ary.index(filename)
334
+ sub_ary = ary[(left + 1)..]
335
+ ret = true if sub_ary&.index(filename)
336
336
  end
337
337
 
338
338
  ret
@@ -376,20 +376,20 @@ module Ykutils
376
376
  dirname.join(basename.to_s + add_string + extname.to_s)
377
377
  end
378
378
 
379
- def determine_encoding(pn)
379
+ def determine_encoding(pathn)
380
380
  encodings = [Encoding::UTF_8, Encoding::EUC_JP, Encoding::Shift_JIS, Encoding::CP932]
381
381
 
382
382
  valid_enc = nil
383
383
  encodings.each do |enc|
384
384
  next if valid_enc
385
385
 
386
- s = pn.expand_path.read(encoding: enc)
386
+ s = pathn.expand_path.read(encoding: enc)
387
387
  next unless s.valid_encoding?
388
388
 
389
389
  begin
390
- cs = s.encode(Encoding::CP932)
390
+ s.encode(Encoding::CP932)
391
391
  valid_enc = enc
392
- rescue StandardError => e
392
+ rescue StandardError
393
393
  # puts "Conversion Error! #{y}"
394
394
  # puts y
395
395
  end
@@ -29,7 +29,7 @@ module Ykutils
29
29
  end
30
30
 
31
31
  def to_hash
32
- h = { "owner" => @owner.to_hash, "group" => @group.to_hash, "other" => @other.to_hash }
32
+ { "owner" => @owner.to_hash, "group" => @group.to_hash, "other" => @other.to_hash }
33
33
  end
34
34
  end
35
35
  end
@@ -1,37 +1,34 @@
1
- require 'ykutils/erubyx'
1
+ require "ykutils/erubyx"
2
2
 
3
3
  module Ykutils
4
4
  module Gridlist
5
- TAMPLETES = { :GRID_DEF =>
6
- { :TEMPLATE => %!
5
+ TAMPLETES = { GRID_DEF: { TEMPLATE: %(
7
6
  .g-<%= row %>-<%= colum %> {
8
7
  grid-row-start: <%= row %>;
9
8
  grid-row-end: ,<%= row + 1 %>;
10
9
  grid-column-start: <%= colum %>;
11
10
  grid-column-end: <%= colum + 1 %>;
12
11
  }
13
- !, :OBJ => nil } }
12
+ ), OBJ: nil } }.freeze
14
13
 
15
14
  module_function
16
15
 
17
16
  def make_one_grid(hash, row, colum)
18
- unless hash[:OBJ]
19
- hash[:OBJ] = Tilt::ErubiTemplate.new { hash[:TEMPLATE] }
20
- end
17
+ hash[:OBJ] = Tilt::ErubiTemplate.new { hash[:TEMPLATE] } unless hash[:OBJ]
21
18
  hash[:OBJ].render(Object.new, { row: row, colum: colum })
22
19
  end
23
20
 
24
21
  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|
22
+ (min_row..max_row).map do |row|
23
+ (min_colum..max_colum).map do |colum|
27
24
  # puts "#{row} #{colum}"
28
25
  value_hash = { row: row, colum: colum }
29
26
  # make_one_grid(template_hash, value_hash)
30
27
  # p template_hash
31
28
  # p value_hash
32
- Ykutils::Erubyx::erubi_render(template_hash, scope, value_hash)
33
- }
34
- }
29
+ Ykutils::Erubyx.erubi_render(template_hash, scope, value_hash)
30
+ end
31
+ end
35
32
  end
36
33
 
37
34
  def make_grid_list(min_row, max_row, min_colum, max_colum)
@@ -34,7 +34,7 @@ module Ykutils
34
34
  def replace(*args)
35
35
  super(*args)
36
36
  @ary = super.keys
37
- @ary ||= []
37
+ @replace ||= []
38
38
  end
39
39
 
40
40
  def delete(ind, &block)
@@ -50,9 +50,5 @@ module Ykutils
50
50
 
51
51
  super
52
52
  end
53
-
54
- def reject(&block)
55
- super
56
- end
57
53
  end
58
54
  end
data/lib/ykutils/lines.rb CHANGED
@@ -4,7 +4,7 @@ module Ykutils
4
4
  @line_ary = line_ary
5
5
  end
6
6
 
7
- def get_line
7
+ def line
8
8
  @line_ary.shift if @line_ary.size > -1
9
9
  end
10
10
  end
@@ -20,16 +20,16 @@ module Ykutils
20
20
 
21
21
  def setup; end
22
22
 
23
- def get_line
23
+ def line
24
24
  @line_stack.shift if @line_stack.size > -1
25
25
  end
26
26
 
27
27
  def output_f(fname)
28
- if fname
29
- File.open(fname, "w") do |file|
30
- @line_stack.each do |it|
31
- file.write(it.to_s)
32
- end
28
+ return unless fname
29
+
30
+ File.open(fname, "w") do |file|
31
+ @line_stack.each do |it|
32
+ file.write(it.to_s)
33
33
  end
34
34
  end
35
35
  end
@@ -50,10 +50,11 @@ module Ykutils
50
50
  ETC = 100
51
51
 
52
52
  def setup
53
- while (line = @lines.get_line)
53
+ while (line = @lines.line)
54
54
  next if line.strip == ""
55
55
 
56
- if line =~ /^---/
56
+ case line
57
+ when /^---/
57
58
  case @status
58
59
  when HOST_ACCOUNT_START, HOST_ACCOUNT
59
60
  @line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
@@ -66,7 +67,7 @@ module Ykutils
66
67
  @line_stack.push({ "STATUS" => SEPARATOR,
67
68
  "CONTENT" => line })
68
69
  @status = SEPARATOR
69
- elsif line =~ /^\s/
70
+ when /^\s/
70
71
  case @status
71
72
  when HOST_ACCOUNT_START, HOST_ACCOUNT
72
73
  @line_stack.push({ "STATUS" => HOST_ACCOUNT,
@@ -93,7 +94,7 @@ module Ykutils
93
94
  "CONTENT" => line })
94
95
  @status = ETC
95
96
  end
96
- elsif line =~ /^==/
97
+ when /^==/
97
98
  case @status
98
99
  when HOST_ACCOUNT_START, HOST_ACCOUNT
99
100
  @line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
@@ -122,7 +123,7 @@ module Ykutils
122
123
 
123
124
  i = @line_stack.size - 1
124
125
  seeking = true
125
- while i >= 0 and seeking
126
+ while (i >= 0) && seeking
126
127
  case @line_stack[i]["STATUS"]
127
128
  when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
128
129
  @line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
@@ -133,6 +134,7 @@ module Ykutils
133
134
  "CONTENT" => nil })
134
135
  seeking = false
135
136
  when ETC
137
+ seeking = true
136
138
  else
137
139
  seeking = false
138
140
  end
@@ -5,9 +5,7 @@ module Ykytils
5
5
  class DirEntryItem
6
6
  attr_accessor :name, :user, :group, :size, :month, :day, :time, :year, :path, :type, :parent_dir, :valid
7
7
 
8
- def initialize; end
9
-
10
- def parse(str, parent_dir, valid = true)
8
+ def parse(str, parent_dir, valid: true)
11
9
  ary = str.split(/\s+/)
12
10
  perm = ary[0]
13
11
  @type = if perm[0].chr == "d"
@@ -49,11 +47,11 @@ module Ykytils
49
47
  end
50
48
 
51
49
  def directory?
52
- @type === :DIRECTORY
50
+ @type == :DIRECTORY
53
51
  end
54
52
 
55
53
  def file?
56
- @type === :FILE
54
+ @type == :FILE
57
55
  end
58
56
 
59
57
  def owner_perm