rus-admin 0.1.0 → 0.1.1

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: b18c7ccfa78f51109d5412f24af5609e410e1f78056d8db6c015deb680779a77
4
- data.tar.gz: 7b05b29fd765252bf3993aea482890fdffdbf46825ded3afbdc491d2b48ab0d9
3
+ metadata.gz: 23d0abb77618bbe1a1feb2895816c72ad3c63647e1e95a3c9a2a5fb4c731dc38
4
+ data.tar.gz: deb32c1c3018052056805c39d54fe0ab010c4f9e13fbd7d74a10fbe5da2f6661
5
5
  SHA512:
6
- metadata.gz: 1593a7f05ff37a2c0ce8f9dcf0539332f25189ae1273ad07403f75a799acee85079fa0c865a1523fe764edbb13f50d5a28254ef7dce7f7fe839ff431bc1608ef
7
- data.tar.gz: 8c0259c1da8c5734c81e99e87294a2d2406e671e85b6f6c9b8a9a85f78a37dcb2a98455a7c6f4980141d36ed063e9638df4e85008b2da08bb812aff69ebb8508
6
+ metadata.gz: d799d43186de40ca4429ec46c37a3ebf0408384abbd5b64082a1aee0ebb22d15a3109dd1d5c47cd1d336ffacf49683915014a557b6c908792d4c6dc27a9cf378
7
+ data.tar.gz: db5355c99c963e7eb83d2d8665f7e2084db2781949b9d24e98b6fbb2fd5645b36ae871b06fbaa980ad7cbc39f8f49d79e969c326d1df6fc3e844b3d7113b5b7f
data/README.md CHANGED
@@ -4,9 +4,21 @@ Set of helpers for system administration with IRB
4
4
 
5
5
  ## How to install
6
6
 
7
+ Download from GitHub, build gem and install locally
8
+
9
+ ```
10
+ git clone https://www.github.com/alx3dev/rus-admin.git \
11
+ cd rus-admin \
12
+ rake build \
13
+ gem install pkg/rus-admin-0.1.1.gem
14
+ ```
15
+
16
+ Install from rubygems
17
+
7
18
  ```
8
19
  gem install rus-admin
9
20
  ```
21
+
10
22
  Open IRB shell with:
11
23
  ```
12
24
  rus-admin
@@ -53,13 +65,14 @@ pp Find.info.result if Find.info.result.any?
53
65
  How to use:
54
66
 
55
67
  ```ruby
56
- Randompass[20]
68
+ Randpass[20]
57
69
  => "0!ZNiAUZCbjo!#hHeX+XX$eAC=!p"
58
70
  ```
59
71
 
60
72
  **Override**
61
73
  Override method `capitalize!`, make it work without downcase of other characters.
62
74
  Available in classes: `String, Symbol, Array`. If used in array, hashes and integers are skipped.
75
+ Read source code for documentation
63
76
 
64
77
  ```ruby
65
78
  # override method #capitalize!
@@ -29,7 +29,7 @@
29
29
  # puts "No match for #{action.params}"
30
30
  # end
31
31
  #
32
- class Find
32
+ module Find
33
33
  Result = Struct.new(:params, :path, :result)
34
34
 
35
35
  COMPARATION = %i[equal include start_with end_with].freeze
@@ -105,6 +105,7 @@ class Find
105
105
  add string, line_no if add_to
106
106
  end
107
107
 
108
+ # rubocop:disable Metrics/CyclomaticComplexity
108
109
  def check_line(line, string, type)
109
110
  case type
110
111
  when :include then true if line.include? string
@@ -113,6 +114,7 @@ class Find
113
114
  when :end_with then true if line.end_with? string
114
115
  end
115
116
  end
117
+ # rubocop:enable Metrics/CyclomaticComplexity
116
118
 
117
119
  def add(param, line_no)
118
120
  @found[param] = Array(@found[param]) | Array(line_no)
@@ -2,36 +2,45 @@
2
2
 
3
3
  require 'securerandom'
4
4
 
5
+ # Generate random password with SecureRandom#base64 and a few
6
+ # random special characters. Method #randpass is defined as
7
+ # class and instance method, so you can call it or include it.
8
+ #
9
+ # @note Always shuffle #base64 if it has less than 16 chars, because they end with '=='
10
+ #
5
11
  module Randpass
12
+ # allowed specials. xxx is flag for #add_special_chars
13
+ ARRAY = %w[! # * $ % _ @ xxx].freeze
14
+
15
+ # Random number of times try to add random special character.
16
+ # Transform to array, shuffle, and join back to string
17
+ #
18
+ # @param [Integer] number_of_chars **Required**. Number of password characters.
19
+ # @return [String]
20
+ #
21
+ def randpass(number_of_chars)
22
+ Randpass[number_of_chars]
23
+ end
24
+
6
25
  class << self
7
- attr_reader :pass
8
-
9
- # Get random password
10
- # Add special characters to SecureRandom#base64 random string, and shuffle it
11
- #
12
- # @note Always shuffle base64 if it has less than 16 chars, because they end with '=='
13
- #
14
- def [](number_of_chars = 18)
15
- random = SecureRandom.base64(number_of_chars)
16
- rand(5..10).times { random = add_special_chars(random) }
17
- @pass = random.split('').shuffle.join
26
+ # @return [String]
27
+ def randpass(number_of_chars)
28
+ param = SecureRandom.base64(number_of_chars)
29
+ rand(5..10).times do
30
+ param = add_special_chars(param)
31
+ end
32
+ param.split('').shuffle.join
18
33
  end
19
- alias get []
34
+
35
+ alias [] randpass
20
36
 
21
37
  private
22
38
 
23
39
  def add_special_chars(param)
24
- count = SecureRandom.random_number 15_000
25
- char = case count
26
- when 1...1000 then '_'
27
- when 1000...2000 then '!'
28
- when 2000...3000 then '#'
29
- when 3000...4000 then '$'
30
- when 4000...5000 then '%'
31
- when 6000...7000 then '?'
32
- else return param
33
- end
34
- param[rand(param.size)] = char
40
+ char = ARRAY.shuffle[rand(ARRAY.size)]
41
+ return param if char == 'xxx'
42
+
43
+ param[rand(param.size)] = char.to_s
35
44
  param
36
45
  end
37
46
  end
data/lib/rus/admin.rb CHANGED
@@ -1,20 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'version' unless defined? Rus::Admin::VERSION
4
+
4
5
  require_relative 'admin/find' unless defined? Find
5
6
  require_relative 'admin/randpass' unless defined? Randpass
6
7
 
7
- module Rus
8
- module Admin
9
- class << self
10
- def override?
11
- @override == true
12
- end
13
-
14
- def override!
15
- require_relative 'override/override'
16
- @override = true
17
- end
18
- end
19
- end
20
- end
8
+ require_relative 'override' unless defined? Rus.override?
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ruby capitalize! upcase first character, but perform
4
+ # downcase on other characters. This is my workaround.
5
+ class String
6
+ def capitalize!
7
+ self[0] = self[0].upcase
8
+ self
9
+ end
10
+ end
11
+
12
+ # Ruby capitalize! upcase first character, but perform
13
+ # downcase on other characters. Also, when capitalizing :symbols,
14
+ # I mostly need String to be returned.
15
+ class Symbol
16
+ def capitalize!
17
+ to_s.capitalize!
18
+ end
19
+ end
20
+
21
+ # Ruby capitalize! upcase first character, but perform
22
+ # downcase on other characters. And we cant capitalize array.
23
+ # This method convert all to strings, and capitalize.
24
+ class Array
25
+ def capitalize!
26
+ map! do |x|
27
+ x = x.to_s if x.is_a? Integer
28
+ x.capitalize!
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Style/Documentation
4
+ module Rus
5
+ class << self
6
+ # check if default classes are overridden
7
+ def override?
8
+ @override == true
9
+ end
10
+ alias overridden? override?
11
+
12
+ # Override default classes: *string, symbol, array*
13
+ # with capitalize! method - without any downcase.
14
+ # @return [Boolean] False if already overridden, otherwise true.
15
+ def override
16
+ return false if override?
17
+
18
+ require_relative 'override/main'
19
+ @override = true
20
+ end
21
+ alias override! override
22
+ end
23
+ end
24
+ # rubocop:enable Style/Documentation
data/lib/rus/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rus
4
4
  module Admin
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rus-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alx3dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-20 00:00:00.000000000 Z
11
+ date: 2022-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -40,7 +40,8 @@ files:
40
40
  - lib/rus/admin.rb
41
41
  - lib/rus/admin/find.rb
42
42
  - lib/rus/admin/randpass.rb
43
- - lib/rus/override/override.rb
43
+ - lib/rus/override.rb
44
+ - lib/rus/override/main.rb
44
45
  - lib/rus/version.rb
45
46
  homepage: https://www.github.com/alx3dev/rus-admin
46
47
  licenses:
@@ -49,7 +50,7 @@ metadata:
49
50
  homepage_uri: https://www.github.com/alx3dev/rus-admin
50
51
  source_code_uri: https://www.github.com/alx3dev/rus-admin
51
52
  changelog_uri: https://www.github.com/alx3dev/rus-admin/CHANGELOG.md
52
- documentation_uri: https://www.rubydoc.info/gems/rus-admin/0.1.0
53
+ documentation_uri: https://www.rubydoc.info/gems/rus-admin/0.1.1
53
54
  post_install_message:
54
55
  rdoc_options: []
55
56
  require_paths:
@@ -58,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
59
  requirements:
59
60
  - - ">="
60
61
  - !ruby/object:Gem::Version
61
- version: '2.7'
62
+ version: '2.6'
62
63
  - - "<"
63
64
  - !ruby/object:Gem::Version
64
65
  version: '3.2'
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class String
4
- def capitalize!
5
- self[0] = self[0].upcase
6
- self
7
- end
8
- end
9
-
10
- class Symbol
11
- def capitalize!
12
- String.new(name).capitalize!.to_sym
13
- end
14
- end
15
-
16
- class Array
17
- def capitalize!
18
- each do |x|
19
- x.capitalize! if x.instance_of?(String) || x.instance_of?(Symbol)
20
- end
21
- end
22
- end