fake_data 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/Guardfile +29 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +15 -0
- data/bin/console +10 -0
- data/bin/rake +4 -0
- data/bin/setup +8 -0
- data/fake_data.gemspec +42 -0
- data/lib/fake_data.rb +27 -0
- data/lib/fake_data/method.rb +132 -0
- data/lib/fake_data/method/control.rb +60 -0
- data/lib/fake_data/method/faker.rb +20 -0
- data/lib/fake_data/structure.rb +135 -0
- data/lib/fake_data/version.rb +3 -0
- metadata +204 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6cdaac93546def3c7d0c48e9c30ed2b003e85b7b
|
4
|
+
data.tar.gz: 70ca387710795bd8c7c8facdb0471ae446e53e4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5710d6c44169fa92d868c725ed68f980990a6e897bc9526d8c726a38f7f11d6342e2df2581846a742e3e88f0beed1bc220e80ae5bafa3e04f217d7d4734f1917
|
7
|
+
data.tar.gz: 9af00b36aea62ddfa43208ede20df3aa6414e6b1701f4c80d65926ab78fe59b160836253776cec04d1655405470848b12d9feb3a4a381cb514b2db29b5b90e09
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
fake_data
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
guard :minitest do
|
19
|
+
# watch /lib/ files
|
20
|
+
watch(%r{^lib/(.+)\.rb$}) { |m|
|
21
|
+
"test/fake_data_test.rb"
|
22
|
+
}
|
23
|
+
|
24
|
+
|
25
|
+
# watch /spec/ files
|
26
|
+
watch(%r{^test/(.+).rb$}) do |m|
|
27
|
+
"test/#{m[1]}.rb"
|
28
|
+
end
|
29
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 David Schovanec
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/schovi/FakeData.png?branch=master)](https://travis-ci.org/schovi/FakeData)
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/fake_data.png)](http://badge.fury.io/rb/fake_data)
|
4
|
+
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/schovi/FakeData/badge.png)](https://coveralls.io/r/schovi/FakeData)
|
6
|
+
|
7
|
+
# FakeData
|
8
|
+
|
9
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fake_data`. To experiment with that code, run `bin/console` for an interactive prompt.
|
10
|
+
|
11
|
+
TODO: Delete this and the text above, and describe your gem
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'fake_data'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install fake_data
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
TODO: Write usage instructions here
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rake test` to run the tests, or `guard` to run . You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec fake_data` to use the gem in this directory, ignoring other installed copies of this gem.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/schovi/fake_data. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
42
|
+
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
# Load FakeData rake tasks
|
5
|
+
Rake.add_rakelib 'lib/tasks'
|
6
|
+
|
7
|
+
# `rake test` to run tests
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.libs << "test"
|
10
|
+
t.libs << "lib"
|
11
|
+
t.test_files = FileList['test/**/*_test.rb']
|
12
|
+
end
|
13
|
+
|
14
|
+
# or just `rake` to run tests
|
15
|
+
task :default => :test
|
data/bin/console
ADDED
data/bin/rake
ADDED
data/bin/setup
ADDED
data/fake_data.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fake_data/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fake_data"
|
8
|
+
spec.version = FakeData::VERSION
|
9
|
+
spec.authors = ["David Schovanec"]
|
10
|
+
spec.email = ["schovanec@schovi.cz"]
|
11
|
+
|
12
|
+
spec.summary = %q{Universal random data generator}
|
13
|
+
spec.description = %q{Universal random data generator. Supports String, Array, Hash, repeat and maybe on part of structure}
|
14
|
+
spec.homepage = "https://github.com/schovi/fake_data"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# # delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").
|
26
|
+
reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "minitest", "5.8.4"
|
34
|
+
spec.add_development_dependency 'minitest-reporters', '1.1.8'
|
35
|
+
spec.add_development_dependency 'minitest-ci', '3.0.3'
|
36
|
+
spec.add_development_dependency 'guard', '2.13.0'
|
37
|
+
spec.add_development_dependency 'guard-minitest', '2.4.4'
|
38
|
+
spec.add_development_dependency 'terminal-notifier-guard', '1.7.0'
|
39
|
+
spec.add_development_dependency 'pry', '0.10.3'
|
40
|
+
|
41
|
+
spec.add_runtime_dependency 'faker', '1.6.3'
|
42
|
+
end
|
data/lib/fake_data.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "faker"
|
2
|
+
require "fake_data/version"
|
3
|
+
require "fake_data/structure"
|
4
|
+
require "fake_data/method"
|
5
|
+
|
6
|
+
# This is required. Sometimes Faker throws error on missing locale.
|
7
|
+
I18n.reload!
|
8
|
+
|
9
|
+
module FakeData
|
10
|
+
class << self
|
11
|
+
def locale=(locale)
|
12
|
+
Faker::Config.locale = locale
|
13
|
+
end
|
14
|
+
|
15
|
+
def once object
|
16
|
+
generator(object).call
|
17
|
+
end
|
18
|
+
|
19
|
+
def generator object
|
20
|
+
Structure.object_to_lambda(object)
|
21
|
+
end
|
22
|
+
|
23
|
+
def debug object
|
24
|
+
Structure.object_to_source(object)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require "fake_data/method/faker"
|
2
|
+
require "fake_data/method/control"
|
3
|
+
|
4
|
+
module FakeData
|
5
|
+
class Method
|
6
|
+
# TODO: problem with parsing "test()" => method = test; arguments = ["()"]
|
7
|
+
METHOD_MATCHER = /((?<klass>[a-z_.:]+)\.)?(?<method>[a-z_=\?]+)\s*(\((?<args1>.+)\)|(?<args2>.+))?\s*/i
|
8
|
+
LEFT_BRACKET_MATCHER = /^\(/
|
9
|
+
RIGHT_BRACKET_MATCHER = /\)$/
|
10
|
+
# TODO: better argument splitting
|
11
|
+
# does not works with arrays, hash etc method(1, [1, 2])
|
12
|
+
ARGUMENT_SPLIT_MATCHER = /\s*,\s*/
|
13
|
+
|
14
|
+
attr_reader :raw, :klass, :method, :arguments
|
15
|
+
|
16
|
+
def initialize raw
|
17
|
+
@raw = raw
|
18
|
+
@klass, @method, @arguments = parse(@raw)
|
19
|
+
end
|
20
|
+
|
21
|
+
def source
|
22
|
+
make_call(klass, method, arguments)
|
23
|
+
end
|
24
|
+
|
25
|
+
def call
|
26
|
+
eval(source)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
source
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def parse raw
|
36
|
+
match = resolve(raw)
|
37
|
+
klass = resolve_klass(match["klass"])
|
38
|
+
method = resolve_method(klass, match["method"])
|
39
|
+
arguments = resolve_arguments(klass, method, match["args1"] || match["args2"])
|
40
|
+
|
41
|
+
return [klass, method, arguments]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Resolvers
|
45
|
+
def resolve raw
|
46
|
+
match = raw.match(METHOD_MATCHER)
|
47
|
+
raise_custom NoMethodError, "missing method" unless match
|
48
|
+
match
|
49
|
+
end
|
50
|
+
|
51
|
+
def resolve_klass klass_string
|
52
|
+
if klass = parse_klass(klass_string)
|
53
|
+
begin
|
54
|
+
eval(klass)
|
55
|
+
rescue NameError
|
56
|
+
raise_custom NameError, "'#{klass}' is not valid class"
|
57
|
+
rescue
|
58
|
+
end
|
59
|
+
|
60
|
+
klass
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def resolve_method klass, method_string
|
65
|
+
raise_custom NoMethodError, "missing method" unless method_string
|
66
|
+
|
67
|
+
method = parse_method(klass, method_string)
|
68
|
+
call = make_call(klass, method)
|
69
|
+
|
70
|
+
begin
|
71
|
+
eval(call)
|
72
|
+
rescue NameError, NoMethodError
|
73
|
+
raise_custom NoMethodError, "'#{call}' is not valid method"
|
74
|
+
rescue
|
75
|
+
end
|
76
|
+
|
77
|
+
method_string
|
78
|
+
end
|
79
|
+
|
80
|
+
def resolve_arguments klass, method, arguments_string
|
81
|
+
arguments = parse_arguments(klass, method, arguments_string)
|
82
|
+
call = make_call(klass, method, arguments)
|
83
|
+
|
84
|
+
begin
|
85
|
+
eval(call)
|
86
|
+
rescue ArgumentError
|
87
|
+
raise_custom ArgumentError, "'#{call}' has #{ex.message}"
|
88
|
+
rescue
|
89
|
+
end
|
90
|
+
|
91
|
+
arguments
|
92
|
+
end
|
93
|
+
|
94
|
+
# Parsers
|
95
|
+
def parse_klass klass_string
|
96
|
+
return nil unless klass_string
|
97
|
+
parts = klass_string.split("::").map {|s| s.split(".")}.flatten
|
98
|
+
"::#{parts.map {|s| camelize(s)}.join("::")}"
|
99
|
+
end
|
100
|
+
|
101
|
+
def parse_method klass, method_string
|
102
|
+
# TODO make some validations
|
103
|
+
method_string
|
104
|
+
end
|
105
|
+
|
106
|
+
def parse_arguments klass, method, arguments_string
|
107
|
+
if arguments_string
|
108
|
+
arguments_string.
|
109
|
+
strip.
|
110
|
+
gsub(LEFT_BRACKET_MATCHER, '').
|
111
|
+
gsub(RIGHT_BRACKET_MATCHER, '').
|
112
|
+
split(ARGUMENT_SPLIT_MATCHER)
|
113
|
+
else
|
114
|
+
[]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Helpers
|
119
|
+
def camelize(str)
|
120
|
+
str.split('_').map {|w| w.capitalize}.join
|
121
|
+
end
|
122
|
+
|
123
|
+
def raise_custom error, reason
|
124
|
+
raise error, "FakeData: can't parse '#{raw}'. Reason: #{reason}."
|
125
|
+
end
|
126
|
+
|
127
|
+
def make_call klass, method, arguments = []
|
128
|
+
call = klass ? "#{klass}.#{method}" : method
|
129
|
+
"#{call}(#{arguments.join(", ")})"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module FakeData
|
2
|
+
class Method
|
3
|
+
class Control < FakeData::Method
|
4
|
+
|
5
|
+
attr_reader :call_block
|
6
|
+
class << self
|
7
|
+
def repeat(count, params = {}, &block)
|
8
|
+
if count.is_a?(Range)
|
9
|
+
count = rand(count)
|
10
|
+
end
|
11
|
+
|
12
|
+
result = count.times.map do
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
|
16
|
+
result.length == 0 && params[:nil] ? nil : result
|
17
|
+
end
|
18
|
+
|
19
|
+
def maybe probability = 50, &block
|
20
|
+
if probability <= 0
|
21
|
+
raise "Probability must be greater than 0%"
|
22
|
+
elsif probability >= 100
|
23
|
+
raise "Probability must be lesser than 100%"
|
24
|
+
end
|
25
|
+
|
26
|
+
yield if rand(0..100) <= probability
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize raw, block_content = nil, &block
|
31
|
+
super(raw)
|
32
|
+
|
33
|
+
@call_block = if block_given?
|
34
|
+
"#{block.call}"
|
35
|
+
elsif block_content
|
36
|
+
raise "Block does not implements .call" unless block_content.respond_to?(:call)
|
37
|
+
|
38
|
+
"#{block_content}"
|
39
|
+
else
|
40
|
+
raise "Block is not provided"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def source
|
45
|
+
"#{super} do #{@call_block} end" if @call_block
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def raise_custom error, reason
|
51
|
+
raise error, "FakeData: can't parse '#{raw}'. Reason: #{reason}. For usage see: https://github.com/stympy/faker"
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse_klass klass_string
|
55
|
+
raise_custom NameError, "'#{klass_string}' can't be presented" if klass_string
|
56
|
+
"::FakeData::Method::Control"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module FakeData
|
2
|
+
class Method
|
3
|
+
class Faker < FakeData::Method
|
4
|
+
FAKER_MATCH = /Faker/i
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def raise_custom error, reason
|
9
|
+
raise error, "FakeData: can't parse '#{raw}'. Reason: #{reason}. For usage see: https://github.com/stympy/faker"
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse_klass klass_string
|
13
|
+
raise_custom NameError, "missing faker class" unless klass_string
|
14
|
+
klass = super(klass_string)
|
15
|
+
klass = "::Faker#{klass}" unless klass =~ FAKER_MATCH
|
16
|
+
klass
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module FakeData
|
2
|
+
class Structure
|
3
|
+
FAKER_MATCHER = /\%{(?<content>.*?)\}/
|
4
|
+
|
5
|
+
class << self
|
6
|
+
# Makes lambda from object
|
7
|
+
def object_to_lambda(object)
|
8
|
+
source_to_lambda(
|
9
|
+
object_to_source(
|
10
|
+
object
|
11
|
+
)
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
# For debug
|
16
|
+
def source_to_lambda(string)
|
17
|
+
eval(string)
|
18
|
+
end
|
19
|
+
|
20
|
+
# For debug
|
21
|
+
def object_to_source(object)
|
22
|
+
result = ""
|
23
|
+
|
24
|
+
result << "lambda do\n"
|
25
|
+
result << build_faker_element(object)
|
26
|
+
result << "\nend"
|
27
|
+
|
28
|
+
result
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def build_faker_element(element)
|
34
|
+
case element
|
35
|
+
when Hash
|
36
|
+
build_faker_hash(element)
|
37
|
+
when Array
|
38
|
+
build_faker_array(element)
|
39
|
+
when String
|
40
|
+
build_faker_string(element)
|
41
|
+
else
|
42
|
+
element
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_faker_hash(element)
|
47
|
+
keys = element.keys
|
48
|
+
|
49
|
+
result = ""
|
50
|
+
|
51
|
+
if keys.length == 1 && match = keys.first.to_s.match(FAKER_MATCHER)
|
52
|
+
method = FakeData::Method::Control.new(match["content"]) do build_faker_element(element[keys.first]) end
|
53
|
+
|
54
|
+
result << "#{method}"
|
55
|
+
else
|
56
|
+
result << "{"
|
57
|
+
|
58
|
+
result << element.map do |key, value|
|
59
|
+
"\"#{key.to_s}\" => #{build_faker_element(value)}"
|
60
|
+
end.join(",")
|
61
|
+
|
62
|
+
result << "}"
|
63
|
+
end
|
64
|
+
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_faker_array(element)
|
69
|
+
result = ""
|
70
|
+
|
71
|
+
result << "["
|
72
|
+
|
73
|
+
result << element.map do |value|
|
74
|
+
build_faker_element(value)
|
75
|
+
end.join(",")
|
76
|
+
|
77
|
+
result << "]"
|
78
|
+
|
79
|
+
result
|
80
|
+
end
|
81
|
+
|
82
|
+
def build_faker_string(source)
|
83
|
+
partitions = partition_by_faker_matcher(source)
|
84
|
+
|
85
|
+
if partitions.length == 1 && faker = partitions.first[:faker]
|
86
|
+
return faker.to_s
|
87
|
+
end
|
88
|
+
|
89
|
+
result = partitions.map do |partition|
|
90
|
+
if faker = partition[:faker]
|
91
|
+
"\#\{#{faker}\}"
|
92
|
+
else
|
93
|
+
partition[:text]
|
94
|
+
end
|
95
|
+
end.join
|
96
|
+
|
97
|
+
if partitions.length == 1 && partitions[0][:faker]
|
98
|
+
result
|
99
|
+
else
|
100
|
+
"\"#{result}\""
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Split faker string into partitions
|
105
|
+
# input < "some text %{number.number(10)} another %{name.name} end"
|
106
|
+
# output > [
|
107
|
+
# { text: "some text " },
|
108
|
+
# { faker: "Faker::Number.number(10)" },
|
109
|
+
# { text: " another " },
|
110
|
+
# { faker: "Faker::Name.name" },
|
111
|
+
# { text: " end" }
|
112
|
+
# ]
|
113
|
+
def partition_by_faker_matcher string = ""
|
114
|
+
result = []
|
115
|
+
|
116
|
+
while true
|
117
|
+
text, faker_placer, string = string.partition(FAKER_MATCHER)
|
118
|
+
|
119
|
+
if text.length > 0
|
120
|
+
result.push({ text: text })
|
121
|
+
end
|
122
|
+
|
123
|
+
if faker_placer.length > 0
|
124
|
+
match = faker_placer.match(FAKER_MATCHER)
|
125
|
+
result.push({ faker: Method::Faker.new(match[1]) })
|
126
|
+
end
|
127
|
+
|
128
|
+
break if string.length == 0
|
129
|
+
end
|
130
|
+
|
131
|
+
result
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fake_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Schovanec
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.8.4
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.8.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-reporters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.8
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.1.8
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-ci
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.13.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.13.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.4.4
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.4.4
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: terminal-notifier-guard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.7.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.7.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.10.3
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.10.3
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: faker
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.6.3
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.6.3
|
153
|
+
description: Universal random data generator. Supports String, Array, Hash, repeat
|
154
|
+
and maybe on part of structure
|
155
|
+
email:
|
156
|
+
- schovanec@schovi.cz
|
157
|
+
executables: []
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".gitignore"
|
162
|
+
- ".ruby-gemset"
|
163
|
+
- ".ruby-version"
|
164
|
+
- ".travis.yml"
|
165
|
+
- Gemfile
|
166
|
+
- Guardfile
|
167
|
+
- LICENSE.txt
|
168
|
+
- README.md
|
169
|
+
- Rakefile
|
170
|
+
- bin/console
|
171
|
+
- bin/rake
|
172
|
+
- bin/setup
|
173
|
+
- fake_data.gemspec
|
174
|
+
- lib/fake_data.rb
|
175
|
+
- lib/fake_data/method.rb
|
176
|
+
- lib/fake_data/method/control.rb
|
177
|
+
- lib/fake_data/method/faker.rb
|
178
|
+
- lib/fake_data/structure.rb
|
179
|
+
- lib/fake_data/version.rb
|
180
|
+
homepage: https://github.com/schovi/fake_data
|
181
|
+
licenses:
|
182
|
+
- MIT
|
183
|
+
metadata: {}
|
184
|
+
post_install_message:
|
185
|
+
rdoc_options: []
|
186
|
+
require_paths:
|
187
|
+
- lib
|
188
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
requirements: []
|
199
|
+
rubyforge_project:
|
200
|
+
rubygems_version: 2.5.1
|
201
|
+
signing_key:
|
202
|
+
specification_version: 4
|
203
|
+
summary: Universal random data generator
|
204
|
+
test_files: []
|