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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 724bcba5bca34b1c458a9a96a63e3b2f5add77642cc6bdb10c68636a8c2f2e3e
4
- data.tar.gz: 1619a18b41368f44345ae3cfd91f28003aa9ffd035eb1840d2d4bcc953100b89
3
+ metadata.gz: d589599e24247e2427e4c65151ce83ba44b72350234d3494db28cdb474f56b94
4
+ data.tar.gz: fbb5c776815c9dd74c0b5e6af0d552868089a18cc47bbfa9fffddcd95280a572
5
5
  SHA512:
6
- metadata.gz: 7205c437919dcd3f1cc9b203ca81b53887a8a2c87a6c5c64821c901b09ccd453ded45fff8279df3c4bb6eca343909f2e8f70884477d54c4893fd333469121114
7
- data.tar.gz: f4109ebebecb364f1b41da0038bb71ad7dc787a334d612d5d368eb8684dfc4f64b20f28b7d52c2e32250e3e0b8ed2b9746ae1901aa952b2f6d669a9c58e35780
6
+ metadata.gz: 2b055422318f8c22e69a627e6f2ae4ed5dade088e97bfd0fe4db92c96648038105363d09b061987d67a3de51683daad4375289731e101bf78689ea07b06bcaa7
7
+ data.tar.gz: a814cd8ed5d12a289e27eef8f16651f7ca68e6ccafb0796d16c4e7224ab94c4b25aef22e9871b63a6b2d071cd40ae8aff360081ac1d795b3d8af3304d1a1c29e
data/.l.yml ADDED
@@ -0,0 +1,8 @@
1
+ # https://github.com/redding/l.rb
2
+
3
+ linters:
4
+ - name: "Rubocop"
5
+ cmd: "bundle exec rubocop"
6
+ extensions:
7
+ - ".rb"
8
+ cli_abbrev: "u"
@@ -0,0 +1,3 @@
1
+ inherit_gem:
2
+ much-style-guide:
3
+ - "lib/much-style-guide/rubocop.yml"
@@ -0,0 +1 @@
1
+ 2.5.8
data/.t.yml ADDED
@@ -0,0 +1,6 @@
1
+ # https://github.com/redding/t.rb
2
+
3
+ default_cmd: bundle exec assert
4
+ test_dir: test
5
+ test_file_suffixes:
6
+ - "_tests.rb"
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  ruby "~> 2.5"
@@ -9,83 +9,83 @@ module MuchFactory
9
9
  extend self
10
10
 
11
11
  def integer(max = nil)
12
- self.type_cast(Random.integer(max), :integer)
12
+ type_cast(Random.integer(max), :integer)
13
13
  end
14
14
 
15
15
  def float(max = nil)
16
- self.type_cast(Random.float(max), :float)
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 ||= self.type_cast(Random.date_string, :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 ||= self.type_cast(Random.time_string, :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 ||= self.type_cast(Random.datetime_string, :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
- self.type_cast(Random.string(length || 10), :string)
38
+ type_cast(Random.string(length || 10), :string)
39
39
  end
40
40
 
41
41
  def symbol(*args)
42
- self.string(*args).to_sym
42
+ string(*args).to_sym
43
43
  end
44
44
 
45
45
  def text(length = nil)
46
- self.type_cast(Random.string(length || 20), :string)
46
+ type_cast(Random.string(length || 20), :string)
47
47
  end
48
48
 
49
49
  def slug(length = nil)
50
- self.type_cast(Random.string(length || 5), :string)
50
+ type_cast(Random.string(length || 5), :string)
51
51
  end
52
52
 
53
53
  def hex(length = nil)
54
- self.type_cast(Random.hex_string(length), :string)
54
+ type_cast(Random.hex_string(length), :string)
55
55
  end
56
56
 
57
57
  def file_name(length = nil)
58
- self.type_cast(Random.file_name_string(length), :string)
58
+ type_cast(Random.file_name_string(length), :string)
59
59
  end
60
60
 
61
61
  def dir_path(length = nil)
62
- self.type_cast(Random.dir_path_string(length), :string)
62
+ type_cast(Random.dir_path_string(length), :string)
63
63
  end
64
64
 
65
65
  def file_path
66
- self.type_cast(Random.file_path_string, :string)
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
- self.type_cast(Random.url_string(host, length), :string)
72
+ type_cast(Random.url_string(host, length), :string)
73
73
  end
74
74
 
75
75
  def email(domain = nil, length = nil)
76
- self.type_cast(Random.email_string(domain, length), :string)
76
+ type_cast(Random.email_string(domain, length), :string)
77
77
  end
78
78
 
79
79
  def binary
80
- self.type_cast(Random.binary, :binary)
80
+ type_cast(Random.binary, :binary)
81
81
  end
82
82
 
83
83
  def boolean
84
- self.type_cast(Random.integer.even?, :boolean)
84
+ type_cast(Random.integer.even?, :boolean)
85
85
  end
86
86
 
87
87
  def type_cast(value, type)
88
- self.type_converter.send(type, value)
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); input.to_s; end
97
- def self.integer(input); input.to_i; end
98
- def self.float(input); input.to_f; end
99
- def self.datetime(input); DateTime.parse(input.to_s); end
100
- def self.time(input); Time.parse(input.to_s); end
101
- def self.date(input); Date.parse(input.to_s); end
102
- def self.boolean(input); !!input; end
103
- def self.binary(input); input; end
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)].map{ |n| DICTIONARY[rand(DICTIONARY.size)] }.join
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
- self.integer(("f" * length).hex - 1).to_s(16).rjust(length, "0")
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
- "#{self.string(length)}.#{self.string(3)}"
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(*self.string(length).scan(/.{1,4}/))
174
+ File.join(*string(length).scan(/.{1,4}/))
147
175
  end
148
176
 
149
177
  def self.file_path_string
150
- File.join(self.dir_path_string, self.file_name_string)
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, self.dir_path_string(length))
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 ||= "#{self.string(5)}.com"
159
- "#{self.string(length)}@#{domain}"
186
+ domain ||= "#{string(5)}.com"
187
+ "#{string(length)}@#{domain}"
160
188
  end
161
189
 
162
190
  def self.binary
163
- [ self.integer(10000) ].pack("N*")
191
+ [integer(10000)].pack("N*")
164
192
  end
165
193
  end
166
194
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuchFactory
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -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 = `git ls-files`.split($/)
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", ["~> 2.19.0"])
26
+ gem.add_development_dependency("assert", ["~> 2.19.2"])
27
+ gem.add_development_dependency("much-style-guide", ["~> 0.6.0"])
26
28
  end
@@ -4,5 +4,4 @@ require "assert/factory"
4
4
 
5
5
  module Factory
6
6
  extend Assert::Factory
7
-
8
7
  end
@@ -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(/\A\//)
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(/\A#{host}\//)
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.0
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-04 00:00:00.000000000 Z
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.0
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.0
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.1.2
86
+ rubygems_version: 3.2.4
69
87
  signing_key:
70
88
  specification_version: 4
71
89
  summary: An API for generating randomized data.