much-factory 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.l.yml +8 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -0
- data/.t.yml +6 -0
- data/Gemfile +2 -0
- data/lib/much-factory.rb +63 -35
- data/lib/much-factory/version.rb +1 -1
- data/much-factory.gemspec +5 -3
- data/test/support/factory.rb +0 -1
- data/test/unit/much-factory_tests.rb +2 -2
- metadata +23 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d589599e24247e2427e4c65151ce83ba44b72350234d3494db28cdb474f56b94
|
4
|
+
data.tar.gz: fbb5c776815c9dd74c0b5e6af0d552868089a18cc47bbfa9fffddcd95280a572
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b055422318f8c22e69a627e6f2ae4ed5dade088e97bfd0fe4db92c96648038105363d09b061987d67a3de51683daad4375289731e101bf78689ea07b06bcaa7
|
7
|
+
data.tar.gz: a814cd8ed5d12a289e27eef8f16651f7ca68e6ccafb0796d16c4e7224ab94c4b25aef22e9871b63a6b2d071cd40ae8aff360081ac1d795b3d8af3304d1a1c29e
|
data/.l.yml
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.8
|
data/.t.yml
ADDED
data/Gemfile
CHANGED
data/lib/much-factory.rb
CHANGED
@@ -9,83 +9,83 @@ module MuchFactory
|
|
9
9
|
extend self
|
10
10
|
|
11
11
|
def integer(max = nil)
|
12
|
-
|
12
|
+
type_cast(Random.integer(max), :integer)
|
13
13
|
end
|
14
14
|
|
15
15
|
def float(max = nil)
|
16
|
-
|
16
|
+
type_cast(Random.float(max), :float)
|
17
17
|
end
|
18
18
|
|
19
19
|
DAYS_IN_A_YEAR = 365
|
20
20
|
SECONDS_IN_DAY = 24 * 60 * 60
|
21
21
|
|
22
22
|
def date
|
23
|
-
@date ||=
|
23
|
+
@date ||= type_cast(Random.date_string, :date)
|
24
24
|
@date + Random.integer(DAYS_IN_A_YEAR)
|
25
25
|
end
|
26
26
|
|
27
27
|
def time
|
28
|
-
@time ||=
|
28
|
+
@time ||= type_cast(Random.time_string, :time)
|
29
29
|
@time + (Random.float(DAYS_IN_A_YEAR) * SECONDS_IN_DAY).to_i
|
30
30
|
end
|
31
31
|
|
32
32
|
def datetime
|
33
|
-
@datetime ||=
|
33
|
+
@datetime ||= type_cast(Random.datetime_string, :datetime)
|
34
34
|
@datetime + (Random.float(DAYS_IN_A_YEAR) * SECONDS_IN_DAY).to_i
|
35
35
|
end
|
36
36
|
|
37
37
|
def string(length = nil)
|
38
|
-
|
38
|
+
type_cast(Random.string(length || 10), :string)
|
39
39
|
end
|
40
40
|
|
41
41
|
def symbol(*args)
|
42
|
-
|
42
|
+
string(*args).to_sym
|
43
43
|
end
|
44
44
|
|
45
45
|
def text(length = nil)
|
46
|
-
|
46
|
+
type_cast(Random.string(length || 20), :string)
|
47
47
|
end
|
48
48
|
|
49
49
|
def slug(length = nil)
|
50
|
-
|
50
|
+
type_cast(Random.string(length || 5), :string)
|
51
51
|
end
|
52
52
|
|
53
53
|
def hex(length = nil)
|
54
|
-
|
54
|
+
type_cast(Random.hex_string(length), :string)
|
55
55
|
end
|
56
56
|
|
57
57
|
def file_name(length = nil)
|
58
|
-
|
58
|
+
type_cast(Random.file_name_string(length), :string)
|
59
59
|
end
|
60
60
|
|
61
61
|
def dir_path(length = nil)
|
62
|
-
|
62
|
+
type_cast(Random.dir_path_string(length), :string)
|
63
63
|
end
|
64
64
|
|
65
65
|
def file_path
|
66
|
-
|
66
|
+
type_cast(Random.file_path_string, :string)
|
67
67
|
end
|
68
68
|
|
69
69
|
alias_method :path, :dir_path
|
70
70
|
|
71
71
|
def url(host = nil, length = nil)
|
72
|
-
|
72
|
+
type_cast(Random.url_string(host, length), :string)
|
73
73
|
end
|
74
74
|
|
75
75
|
def email(domain = nil, length = nil)
|
76
|
-
|
76
|
+
type_cast(Random.email_string(domain, length), :string)
|
77
77
|
end
|
78
78
|
|
79
79
|
def binary
|
80
|
-
|
80
|
+
type_cast(Random.binary, :binary)
|
81
81
|
end
|
82
82
|
|
83
83
|
def boolean
|
84
|
-
|
84
|
+
type_cast(Random.integer.even?, :boolean)
|
85
85
|
end
|
86
86
|
|
87
87
|
def type_cast(value, type)
|
88
|
-
|
88
|
+
type_converter.send(type, value)
|
89
89
|
end
|
90
90
|
|
91
91
|
def type_converter
|
@@ -93,14 +93,37 @@ module MuchFactory
|
|
93
93
|
end
|
94
94
|
|
95
95
|
module TypeConverter
|
96
|
-
def self.string(input)
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
def self.
|
101
|
-
|
102
|
-
|
103
|
-
|
96
|
+
def self.string(input)
|
97
|
+
input.to_s
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.integer(input)
|
101
|
+
input.to_i
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.float(input)
|
105
|
+
input.to_f
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.datetime(input)
|
109
|
+
DateTime.parse(input.to_s) # rubocop:disable Style/DateTime
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.time(input)
|
113
|
+
Time.parse(input.to_s)
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.date(input)
|
117
|
+
Date.parse(input.to_s)
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.boolean(input)
|
121
|
+
!!input
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.binary(input)
|
125
|
+
input
|
126
|
+
end
|
104
127
|
end
|
105
128
|
|
106
129
|
module Random
|
@@ -127,40 +150,45 @@ module MuchFactory
|
|
127
150
|
end
|
128
151
|
|
129
152
|
DICTIONARY = [*"a".."z"].freeze
|
153
|
+
|
130
154
|
def self.string(length = nil)
|
131
|
-
[*0..((length || 10) - 1)]
|
155
|
+
[*0..((length || 10) - 1)]
|
156
|
+
.map{ |_n|
|
157
|
+
DICTIONARY[rand(DICTIONARY.size)]
|
158
|
+
}
|
159
|
+
.join
|
132
160
|
end
|
133
161
|
|
134
162
|
def self.hex_string(length = nil)
|
135
163
|
length ||= 10
|
136
|
-
|
164
|
+
integer(("f" * length).hex - 1).to_s(16).rjust(length, "0")
|
137
165
|
end
|
138
166
|
|
139
167
|
def self.file_name_string(length = nil)
|
140
168
|
length ||= 6
|
141
|
-
"#{
|
169
|
+
"#{string(length)}.#{string(3)}"
|
142
170
|
end
|
143
171
|
|
144
172
|
def self.dir_path_string(length = nil)
|
145
173
|
length ||= 12
|
146
|
-
File.join(*
|
174
|
+
File.join(*string(length).scan(/.{1,4}/))
|
147
175
|
end
|
148
176
|
|
149
177
|
def self.file_path_string
|
150
|
-
File.join(
|
178
|
+
File.join(dir_path_string, file_name_string)
|
151
179
|
end
|
152
180
|
|
153
181
|
def self.url_string(host = nil, length = nil)
|
154
|
-
File.join(host.to_s,
|
182
|
+
File.join(host.to_s, dir_path_string(length))
|
155
183
|
end
|
156
184
|
|
157
185
|
def self.email_string(domain = nil, length = nil)
|
158
|
-
domain ||= "#{
|
159
|
-
"#{
|
186
|
+
domain ||= "#{string(5)}.com"
|
187
|
+
"#{string(length)}@#{domain}"
|
160
188
|
end
|
161
189
|
|
162
190
|
def self.binary
|
163
|
-
[
|
191
|
+
[integer(10000)].pack("N*")
|
164
192
|
end
|
165
193
|
end
|
166
194
|
end
|
data/lib/much-factory/version.rb
CHANGED
data/much-factory.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
|
-
# -*- encoding: utf-8 -*-
|
4
4
|
lib = File.expand_path("../lib", __FILE__)
|
5
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
6
|
require "much-factory/version"
|
@@ -15,12 +15,14 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.homepage = "https://github.com/redding/much-factory"
|
16
16
|
gem.license = "MIT"
|
17
17
|
|
18
|
-
gem.files
|
18
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
19
|
+
|
19
20
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
21
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
22
|
gem.require_paths = ["lib"]
|
22
23
|
|
23
24
|
gem.required_ruby_version = "~> 2.5"
|
24
25
|
|
25
|
-
gem.add_development_dependency("assert",
|
26
|
+
gem.add_development_dependency("assert", ["~> 2.19.2"])
|
27
|
+
gem.add_development_dependency("much-style-guide", ["~> 0.6.0"])
|
26
28
|
end
|
data/test/support/factory.rb
CHANGED
@@ -129,14 +129,14 @@ module MuchFactory
|
|
129
129
|
segments = u.split("/")
|
130
130
|
|
131
131
|
assert_that(u).is_kind_of(String)
|
132
|
-
assert_that(u).matches(
|
132
|
+
assert_that(u).matches(%r{\A/})
|
133
133
|
assert_that(segments.size).equals(4)
|
134
134
|
segments[1..-1].each{ |s| assert_that(s).matches(/\A[a-z]{4}\Z/) }
|
135
135
|
end
|
136
136
|
|
137
137
|
should "allow passing a host string using `url`" do
|
138
138
|
host = "example.com"
|
139
|
-
assert_that(subject.url(host)).matches(
|
139
|
+
assert_that(subject.url(host)).matches(%r{\A#{host}/})
|
140
140
|
end
|
141
141
|
|
142
142
|
should "allow passing a maximum length using `url`" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-01-
|
12
|
+
date: 2021-01-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: assert
|
@@ -17,14 +17,28 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 2.19.
|
20
|
+
version: 2.19.2
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 2.19.
|
27
|
+
version: 2.19.2
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: much-style-guide
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.6.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.6.0
|
28
42
|
description: An API for generating randomized data.
|
29
43
|
email:
|
30
44
|
- kelly@kellyredding.com
|
@@ -34,6 +48,10 @@ extensions: []
|
|
34
48
|
extra_rdoc_files: []
|
35
49
|
files:
|
36
50
|
- ".gitignore"
|
51
|
+
- ".l.yml"
|
52
|
+
- ".rubocop.yml"
|
53
|
+
- ".ruby-version"
|
54
|
+
- ".t.yml"
|
37
55
|
- Gemfile
|
38
56
|
- LICENSE
|
39
57
|
- README.md
|
@@ -65,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
83
|
- !ruby/object:Gem::Version
|
66
84
|
version: '0'
|
67
85
|
requirements: []
|
68
|
-
rubygems_version: 3.
|
86
|
+
rubygems_version: 3.2.4
|
69
87
|
signing_key:
|
70
88
|
specification_version: 4
|
71
89
|
summary: An API for generating randomized data.
|