tools 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61950a249bdf881c27c25b12ad2fa00a1a367296a9d757e3e5d6a20c02bf215e
4
- data.tar.gz: 7052e69306f06619d14742408f737ee4acb4c058962c1b840fff95160242c660
3
+ metadata.gz: de676d58cf2e9d530a137126d4889ee97548464d5fab8be7b557625cefe69e2f
4
+ data.tar.gz: 94d0bb63e9f471d3bc8896e91711de2a15877144a02e18593dbb22465946e824
5
5
  SHA512:
6
- metadata.gz: 81a58bbe0bd6e1233fa8f6e6929ea3fe594d28001fa580e8ca88583b4f554238ddfe6a0474f31be2f5d0a48e5a038fd0b6ceff364479ae0ba82a5ea46e36a3db
7
- data.tar.gz: ab08b34343251ba9901376dfd60b0019ffc57fdc3369bda0286819c6a299f4b7bf52ed14c469fec75cd7536c8a0b33561a3fe73299c0d91e117e43f057cc3c5c
6
+ metadata.gz: 93d1d598688624b7b187fcc909718252b8630071b5ccf65fbe0802555090ffd2318544a00de4e8f90c6529b4a741bbdcbe76cb2ba620d3f5b4f587946a91cb26
7
+ data.tar.gz: 282fe27e88c0ce4e916efdb669acecb69de02f846f9354b7414670b94b3b01e4b1c0279c594fdb530fe26eaf728f3773bc494bc6fc75cbfca5f58fda43ba48d8
@@ -0,0 +1,11 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - 'test/**/*.rb'
7
+ - 'bin/**/*'
8
+ - 'aux*'
9
+
10
+ Documentation:
11
+ Enabled: false
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'https://artifactory.globoi.com/artifactory/api/gems/gem-repos/'
2
- #source 'https://rubygems.org'
2
+ # source 'https://rubygems.org'
3
3
 
4
4
  # Specify your gem's dependencies in tools.gemspec
5
5
  gemspec
data/Rakefile CHANGED
@@ -1,15 +1,11 @@
1
- # coding: utf-8
2
-
3
-
4
1
  require 'bundler/gem_helper'
5
- Bundler::GemHelper.install_tasks :name => "tools"
2
+ Bundler::GemHelper.install_tasks name: 'tools'
6
3
 
7
- #require 'bundler/gem_tasks'
4
+ # require 'bundler/gem_tasks'
8
5
  require_relative 'lib/tools/version'
9
6
 
10
-
11
7
  # Default.
12
- task :default => :help
8
+ task default: :help
13
9
 
14
10
  # Help.
15
11
  desc 'Help'
@@ -26,7 +22,7 @@ task :dev do
26
22
 
27
23
  Rake::Task['install'].invoke
28
24
 
29
- source = File.dirname(File.absolute_path __FILE__)
25
+ source = File.dirname(File.absolute_path(__FILE__))
30
26
  target = "#{ENV['GEM_HOME']}/gems/tools-#{Tools::VERSION}"
31
27
  target_bin = "#{ENV['GEM_HOME']}/bin/tools"
32
28
  system("rm -f #{target_bin}")
@@ -37,16 +33,14 @@ task :dev do
37
33
  puts 'You may now start editing and testing files from within this repo.'
38
34
  end
39
35
 
40
-
41
- desc "Release the gem in rubygems (DEV)"
36
+ desc 'Release the gem in rubygems (DEV)'
42
37
  task :push do
43
- gem_file = "#{ENV['PWD']}/pkg/tools-#{Tools::VERSION}.gem"
38
+ gem_file = "#{ENV['PWD']}/pkg/tools-#{Tools::VERSION}.gem"
44
39
  gem_server_url = 'https://rubygems.org'
45
40
  system("gem push #{gem_file} --host #{gem_server_url}")
46
41
  end
47
42
 
48
-
49
- desc "Run all minitests."
43
+ desc 'Run all minitests.'
50
44
  task :mini do
51
- system("./test/minitest/run")
52
- end
45
+ system('./test/minitest/run')
46
+ end
data/aux2 CHANGED
@@ -1,10 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- # coding: utf-8
2
+
3
3
  require 'rubygems'
4
4
  require 'tools'
5
5
 
6
-
7
-
8
6
  t = ToolsUtil.new
9
-
10
-
data/bin/tools CHANGED
@@ -1,30 +1,28 @@
1
1
  #!/usr/bin/env ruby
2
- # coding: utf-8
2
+
3
3
  require 'tools'
4
4
  require 'thor'
5
5
 
6
- Signal.trap("INT") {
6
+ Signal.trap('INT') do
7
7
  puts "\n\tNote: You will typically use Signal.trap instead.\n".light_red
8
8
  exit
9
- }
9
+ end
10
10
 
11
- Signal.trap("TERM") {
11
+ Signal.trap('TERM') do
12
12
  puts "\n\tNote: You will typically use Signal.trap instead.\n".light_red
13
13
  exit
14
- }
14
+ end
15
15
 
16
16
  load Tools.files + '/requireds.rb'
17
17
 
18
18
  class Tools_exec < Thor
19
-
20
19
  desc 'help', ''
21
- def help(command='')
20
+ def help(_command = '')
22
21
  puts "\tHELP will be here..... Coming soon....".light_green
23
-
24
22
  end
25
23
 
26
24
  desc 'show', ''
27
- def show(command='')
25
+ def show(_command = '')
28
26
  puts "Gem_path.: #{Tools.gem_path}"
29
27
  puts "Ldap_pass.: #{Tools.ldap_pass}"
30
28
  puts "Ldap_user.: #{Tools.ldap_user}"
@@ -36,8 +34,8 @@ class Tools_exec < Thor
36
34
 
37
35
  desc 'config', ''
38
36
  def config
39
- ap 'config'
40
- # ToolsConfig.config
37
+ ap 'config'
38
+ # ToolsConfig.config
41
39
  end
42
40
 
43
41
  desc 'exec', ''
@@ -49,34 +47,28 @@ class Tools_exec < Thor
49
47
  desc 'console', ''
50
48
  def console
51
49
  ap 'console'
52
- #ToolsConsole.create_console
53
- #ToolsConsole.run_console
50
+ # ToolsConsole.create_console
51
+ # ToolsConsole.run_console
54
52
  end
55
53
 
56
-
57
- def method_missing(method, *args, &block)
58
-
59
-
60
- # ap method
61
- # ap args.extract_option '-v', false #=> 8
62
- # ap args.extract_option '-x' #=> true
63
- # ap args.extract_option '-f' #=> false
64
- # ap args.extract_symbol :json #=> true
65
- # ap args.extract_symbol :yaml #=> false
66
- # ap args.extract_color #=> :yellow
67
- # ap args.extract_color #=> red
68
- # ap args.extract_option_value '--class' #=> 'tools'
69
- # ap args #=> [-c -vcv -v2 -s ]
70
-
71
-
72
- ToolsDisplay.show "To export ldap variables use: ".fix(60,'.'), :cyan
73
- ToolsDisplay.show "export ldap_user=<your_ldap_login> ".fix(65,'.'), :cyan
74
- ToolsDisplay.show "export ldap_pass=<your_ldap_password>".fix(65,'.'), :cyan
75
-
76
-
77
- exit()
54
+ def method_missing(_method, *_args)
55
+ # ap method
56
+ # ap args.extract_option '-v', false #=> 8
57
+ # ap args.extract_option '-x' #=> true
58
+ # ap args.extract_option '-f' #=> false
59
+ # ap args.extract_symbol :json #=> true
60
+ # ap args.extract_symbol :yaml #=> false
61
+ # ap args.extract_color #=> :yellow
62
+ # ap args.extract_color #=> red
63
+ # ap args.extract_option_value '--class' #=> 'tools'
64
+ # ap args #=> [-c -vcv -v2 -s ]
65
+
66
+ ToolsDisplay.show 'To export ldap variables use: '.fix(60, '.'), :cyan
67
+ ToolsDisplay.show 'export ldap_user=<your_ldap_login> '.fix(65, '.'), :cyan
68
+ ToolsDisplay.show 'export ldap_pass=<your_ldap_password>'.fix(65, '.'), :cyan
69
+
70
+ exit
78
71
  end
79
-
80
72
  end
81
73
 
82
74
  begin
@@ -86,4 +78,4 @@ rescue SystemExit => e
86
78
  exit(e.status)
87
79
  rescue Exception => e
88
80
  puts e
89
- end
81
+ end
@@ -35,5 +35,3 @@ require 'tty-editor'
35
35
  require 'tty-prompt'
36
36
  require 'xmlsimple'
37
37
  require 'yaml'
38
-
39
- include Dnsruby
@@ -1,54 +1,42 @@
1
1
  class Array
2
-
3
2
  # Self pop first element.
4
3
  # @return first element
5
4
  def extract_first
6
5
  first = self[0]
7
- self.delete_at(0)
8
- return first
6
+ delete_at(0)
7
+ first
9
8
  end
10
9
 
11
10
  # Self extract symbol.
12
11
  # @param symbol to retrive
13
12
  # @return boolean
14
- def extract_symbol symbol
13
+ def extract_symbol(symbol)
15
14
  status = false
16
- if self.include? symbol
15
+ if include? symbol
17
16
  status = true
18
- self.delete(symbol)
17
+ delete(symbol)
19
18
  end
20
- return status
19
+ status
21
20
  end
22
21
 
23
22
  # Self extract color.
24
23
  # @return boolean
25
24
  def extract_color
26
- colors = String.colors
27
- color = :default
28
- self.each do |argument|
29
- if argument.symbol?
30
- if colors.include? argument
31
- color = argument
32
- self.delete(argument)
33
- return color
34
- end
35
- else
36
- if argument.string?
37
- if argument.start_with? ':'
38
- color_candidate = argument.gsub(':','').to_sym
39
- color = color_candidate if colors.include? color_candidate
40
- self.delete(argument)
41
- return color
42
- end
43
- end
25
+ each do |argument|
26
+ if argument.symbol? && String.colors.include?(argument)
27
+ color = argument
28
+ delete(argument)
29
+ return color
30
+ elsif argument.string? && argument.start_with?(':')
31
+ color_candidate = argument.gsub(':', '').to_sym
32
+ color = color_candidate if String.colors.include? color_candidate
33
+ delete(argument)
34
+ return color
44
35
  end
45
36
  end
46
- return color
37
+ :default
47
38
  end
48
39
 
49
-
50
-
51
-
52
40
  # Self extract option.
53
41
  # @param option to extract.
54
42
  # @param single boolean to repeat
@@ -65,67 +53,59 @@ class Array
65
53
  # args.extract_color => red
66
54
  # args => [-c -vcv -v2 -s ]
67
55
  #
68
- def extract_option option, single = true
56
+ def extract_option(option, single = true)
69
57
  if single
70
58
  result = false
71
- if self.include? option
59
+ if include? option
72
60
  index = self.index(option)
73
- self.delete_at(index)
61
+ delete_at(index)
74
62
  result = true
75
63
  end
76
64
  else
77
65
  result = 0
78
- self.each do |argument|
79
- if argument.to_s.start_with? option
80
- #puts "'#{option}' '#{argument}' #{argument.start_with? option} \n"
81
- search_char = option.sub('-','')
82
- aux_string = argument.to_s.sub('-','')
83
- count = argument.to_s.count(search_char)
84
- if (count == aux_string.size)
85
- result = result + count
86
- #self.delete(argument)
87
- end
66
+ each do |argument|
67
+ next unless argument.to_s.start_with? option
68
+ # puts "'#{option}' '#{argument}' #{argument.start_with? option} \n"
69
+ search_char = option.sub('-', '')
70
+ aux_string = argument.to_s.sub('-', '')
71
+ count = argument.to_s.count(search_char)
72
+ if count == aux_string.size
73
+ result += count
74
+ # self.delete(argument)
88
75
  end
89
-
90
76
  end
91
77
  end
92
- return result
78
+ result
93
79
  end
94
80
 
95
- def extract_option_value option, args={}
81
+ def extract_option_value(option, args = {})
82
+ args[:multiple] = false if args[:multiple].nil?
96
83
 
97
- if args[:multiple].nil?
98
- args[:multiple] = false
99
- end
100
-
101
- if args[:separator].nil?
102
- args[:separator] = '='
103
- end
84
+ args[:separator] = '=' if args[:separator].nil?
104
85
 
105
86
  result = false
106
87
  if args[:multiple]
107
88
  multiple_value = []
108
- while self.include? option
89
+ while include? option
109
90
  index = self.index(option)
110
- self.delete_at(index)
91
+ delete_at(index)
111
92
  result = true
112
- value = self.at(index)
113
- multiple_value << self.at(index).split(args[:separator]).first
114
- multiple_value << self.at(index).split(args[:separator]).last
115
- self.delete_at(index)
93
+ value = at(index)
94
+ multiple_value << at(index).split(args[:separator]).first
95
+ multiple_value << at(index).split(args[:separator]).last
96
+ delete_at(index)
116
97
  end
117
98
  return [result, multiple_value]
118
99
  else
119
- value = nil
120
- while self.include? option
100
+ value = nil
101
+ while include? option
121
102
  index = self.index(option)
122
- self.delete_at(index)
103
+ delete_at(index)
123
104
  result = true
124
- value = self.at(index)
125
- self.delete_at(index)
105
+ value = at(index)
106
+ delete_at(index)
126
107
  end
127
108
  return [result, value]
128
109
  end
129
110
  end
130
-
131
- end
111
+ end
@@ -2,9 +2,7 @@ require 'singleton'
2
2
  class ToolsCache
3
3
  include Singleton
4
4
 
5
- def initialize(options = {})
6
- end
7
-
5
+ def initialize(options = {}); end
8
6
 
9
7
  # Create a cache file in work area
10
8
  #
@@ -12,12 +10,11 @@ class ToolsCache
12
10
  # @param cache_file
13
11
  # @param ttl
14
12
  # @return
15
- def self.create_cache_file cache_name, cache_file, ttl=nil
13
+ def self.create_cache_file(cache_name, cache_file, ttl = nil)
16
14
  cache = Persistent::Cache.new(cache_file, ttl)
17
15
  ToolsUtil.set_variable "#{cache_name}_cache", cache
18
16
  end
19
17
 
20
-
21
18
  # Add a record in a cache work area
22
19
  #
23
20
  # Sample
@@ -41,8 +38,7 @@ class ToolsCache
41
38
  # @param args
42
39
  # @param block
43
40
  # @return
44
- def self.method_missing(method, *args, &block)
45
-
41
+ def self.method_missing(method, *args)
46
42
  cache_name = method.to_s.split('_').first
47
43
  cache_method = method.to_s.split('_').last
48
44
  cache = ToolsUtil.get_variable "#{cache_name}_cache"
@@ -52,16 +48,14 @@ class ToolsCache
52
48
  when 'set'
53
49
  key = args.extract_first
54
50
  values = args.extract_first
55
- unless cache.key?(key)
56
- cache[key] = values
57
- else
51
+ if cache.key?(key)
58
52
  aux = cache[key]
59
53
  case aux.class.to_s
60
54
  when 'Hash'
61
55
  begin
62
56
  aux.merge! values
63
57
  cache[key] = aux
64
- rescue Exception => e
58
+ rescue StandardError => e
65
59
  ToolsDisplay.show "\tError in ToolsCache: #{e.exception}", :light_yellow
66
60
  exit
67
61
  end
@@ -70,15 +64,17 @@ class ToolsCache
70
64
  case values.class.to_s
71
65
  when 'Array'
72
66
  values.each do |value|
73
- aux.insert(-1,value)
67
+ aux.insert(-1, value)
74
68
  end
75
69
  cache[key] = aux
76
70
  else
77
- aux.insert(-1,values)
71
+ aux.insert(-1, values)
78
72
  cache[key] = aux
79
73
  end
80
74
  end
81
75
 
76
+ else
77
+ cache[key] = values
82
78
  end
83
79
 
84
80
  # when 'set'
@@ -125,12 +121,9 @@ class ToolsCache
125
121
  return result
126
122
 
127
123
  when 'clear'
128
- cache.each do |key|
124
+ cache.each do |key|
129
125
  cache[key] = nil
130
126
  end
131
127
  end
132
-
133
128
  end
134
-
135
-
136
- end
129
+ end