footing 0.0.4 → 0.0.5
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/README.md +1 -0
- data/lib/extensions/string.rb +19 -5
- data/lib/footing.rb +7 -1
- metadata +1 -1
data/README.md
CHANGED
data/lib/extensions/string.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
module Footing
|
2
2
|
module String
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
# Generates a random string.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# Footing.util! Footing::String
|
8
|
+
# Footing::String.random_key(100, :reject => ["1", "I", "l", "0", "O"])
|
9
|
+
#
|
10
|
+
# @param [Integer] length The length of the key to generate. Defaults to 12.
|
11
|
+
# @param [Hash] opts
|
12
|
+
# @option opts [Array] :reject A list of characters to omit from the key.
|
13
|
+
# @option opts [Boolean] :upcase Indicates that only use uppercase characters should be used.
|
14
|
+
# @return [String]
|
15
|
+
def random_key(length=12, opts={})
|
16
|
+
@chars ||= [(0..9).to_a, ('a'..'z').to_a, ('A'..'Z').to_a].flatten.map { |c| c.to_s }
|
17
|
+
chars = @chars.reject do |c|
|
18
|
+
c =~ /[a-z]/ if opts[:upcase]
|
19
|
+
end
|
20
|
+
opts[:reject] ||= []
|
21
|
+
opts[:reject] = opts[:reject].map { |c| c.to_s }
|
22
|
+
(1..length).map{ |i| (chars - opts[:reject]).sample }.join
|
9
23
|
end
|
10
24
|
|
11
25
|
# Escapes a series of chars in the current string.
|
data/lib/footing.rb
CHANGED
@@ -59,7 +59,13 @@ module Footing
|
|
59
59
|
|
60
60
|
mod.instance_methods(false).each do |method|
|
61
61
|
eigen.send :define_method, method do |*args|
|
62
|
-
|
62
|
+
o = args.first || proxy
|
63
|
+
m = proxy_eigen.instance_method(method)
|
64
|
+
if m.parameters.empty?
|
65
|
+
m.bind(o).call
|
66
|
+
else
|
67
|
+
m.bind(o).call(*args)
|
68
|
+
end
|
63
69
|
end
|
64
70
|
end
|
65
71
|
end
|