subroutine-factory 0.1.7 → 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.
- checksums.yaml +4 -4
- data/lib/subroutine/factory.rb +26 -4
- data/lib/subroutine/factory/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc88dc64c89f0f831b0ebbe437649c866edb2ca87a58f953b355a27b453abbb0
|
4
|
+
data.tar.gz: e6671efa5cdc98c54098dc5518db9e304ce2554062b980fc60203df635e9cc15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fb7d4c79e01fc7fbd5459d7d145511d6cb32140da3268eef9d8b16f402bf7ff912b2b96675966426b0eafc3aaec6f4f15c4279c4cc706c7bb7d3b171e4576b5
|
7
|
+
data.tar.gz: 8fe2680a14be76556bfe8c81ffe95b3312f9c52a7d2965c1fe665edf2baed874332ceb100e16a6f6ba8700893965bc8e3a06c4807e90fb10a41bff573c10f43f
|
data/lib/subroutine/factory.rb
CHANGED
@@ -60,14 +60,36 @@ module Subroutine
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def self.random(
|
63
|
+
def self.random(random_options = {}, &lambda)
|
64
64
|
if block_given?
|
65
|
-
proc
|
66
|
-
x =
|
65
|
+
proc do |*options|
|
66
|
+
x = build_random(random_options)
|
67
67
|
lambda.call(*[x, *options].compact)
|
68
68
|
end
|
69
69
|
else
|
70
|
-
|
70
|
+
build_random(random_options)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
RANDOM_FUNCTION_TYPES = %i[alphanumeric numeric alpha]
|
75
|
+
ALPHAS = ("a".."z").to_a
|
76
|
+
NUMERICS = (0..9).to_a
|
77
|
+
ALPHANUMERICS = NUMERICS + ALPHAS
|
78
|
+
def self.build_random(length: 8, type: :alphanumeric)
|
79
|
+
raise ArgumentError, ":type must be one of #{RANDOM_FUNCTION_TYPES.inspect}" unless RANDOM_FUNCTION_TYPES.include?(type.to_sym)
|
80
|
+
|
81
|
+
source = (
|
82
|
+
case type.to_sym
|
83
|
+
when :alphanumeric then ALPHANUMERICS
|
84
|
+
when :numeric then NUMERICS
|
85
|
+
when :alpha then ALPHAS
|
86
|
+
end
|
87
|
+
)
|
88
|
+
|
89
|
+
length.times.inject(+"") do |memo, _i|
|
90
|
+
x = source.sample.to_s
|
91
|
+
x = x.upcase if rand(2) == 1
|
92
|
+
memo << x
|
71
93
|
end
|
72
94
|
end
|
73
95
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subroutine-factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: subroutine
|
@@ -136,8 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
|
-
|
140
|
-
rubygems_version: 2.7.7
|
139
|
+
rubygems_version: 3.0.6
|
141
140
|
signing_key:
|
142
141
|
specification_version: 4
|
143
142
|
summary: Test factories for ops using Subroutine Ops
|