subroutine-factory 0.1.7 → 0.1.8

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: 1b14771d9c6ef402e75be72a97d4fe69e39c62dd17a73313db4ff2ba0ca94ff8
4
- data.tar.gz: 302c8b922d9f59957637c3698f5f4707a6e08155a610d5e19747272e0bcad993
3
+ metadata.gz: dc88dc64c89f0f831b0ebbe437649c866edb2ca87a58f953b355a27b453abbb0
4
+ data.tar.gz: e6671efa5cdc98c54098dc5518db9e304ce2554062b980fc60203df635e9cc15
5
5
  SHA512:
6
- metadata.gz: ce4b512c59cae0c7526a78e15ef5f38a7d5ddc9f6a4064fd814c3503e9234065724f355bd94765df7490c53014ac86bad28c03feb4a7c2817e8d084d08215faa
7
- data.tar.gz: 9928f39fc0498d13806f9212a4de3343051d542f67ed449b1a8a20578e06bf22ce198153271da02f873e705b0f67f6327c0718a7bb9985525dd0ce05587f985c
6
+ metadata.gz: 8fb7d4c79e01fc7fbd5459d7d145511d6cb32140da3268eef9d8b16f402bf7ff912b2b96675966426b0eafc3aaec6f4f15c4279c4cc706c7bb7d3b171e4576b5
7
+ data.tar.gz: 8fe2680a14be76556bfe8c81ffe95b3312f9c52a7d2965c1fe665edf2baed874332ceb100e16a6f6ba8700893965bc8e3a06c4807e90fb10a41bff573c10f43f
@@ -60,14 +60,36 @@ module Subroutine
60
60
  end
61
61
  end
62
62
 
63
- def self.random(length: 8, &lambda)
63
+ def self.random(random_options = {}, &lambda)
64
64
  if block_given?
65
- proc do |*options|
66
- x = ::SecureRandom.hex[0...length]
65
+ proc do |*options|
66
+ x = build_random(random_options)
67
67
  lambda.call(*[x, *options].compact)
68
68
  end
69
69
  else
70
- ::SecureRandom.hex[0...length]
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
 
@@ -3,7 +3,7 @@
3
3
  module Subroutine
4
4
  module Factory
5
5
 
6
- VERSION = "0.1.7"
6
+ VERSION = "0.1.8"
7
7
 
8
8
  end
9
9
  end
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.7
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: 2019-10-10 00:00:00.000000000 Z
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
- rubyforge_project:
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