faker-cli 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c7b2adf410b629671ffea5c58d1a12dd20c0c0e
4
+ data.tar.gz: a211b0d7940d336003339ce08316faec88f6dfc5
5
+ SHA512:
6
+ metadata.gz: 6e684b26ea68e43437372b1c4a5c8ca5bfa0c90ca76159df1df7701660f3447be537e8cc1bd14bf9d3d7d3330bd25b4ce24413045d5e663dfd344241aa27f538
7
+ data.tar.gz: 2e9b49978750f33dfa00a0c44afae04b58f45456514961576b43faf4579852b4ae4f455d2355cecf1e58c1faa57797c5f23f353f24f863a4fce9af4b295f7c64
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in faker-cli.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tobias Witt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # Faker::Cli
2
+
3
+ This tool uses [Faker](https://github.com/stympy/faker) to generate a json
4
+ array of json objects with special fields and faked values.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'faker-cli'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install faker-cli
19
+
20
+ ## Usage
21
+
22
+ faker-cli [-n NUM-ENTRIES] DEF1 DEF2 ... DEFN
23
+
24
+ The value for `-n` defaults to 10. The above command will create `-n` entries
25
+ with fields defined by `DEF1` to `DEFN`.
26
+
27
+ ### DEF
28
+
29
+ A DEF has the form
30
+
31
+ <name>:<Faker-Module>.<Faker-Method>
32
+
33
+ or
34
+
35
+ <name>:<Faker-Module>.<Faker-Method>(param1, param2)
36
+
37
+ * `name` is the name of the objects key
38
+ * `Faker-Module` is the name of the [Faker](https://github.com/stympy/faker) module (e.g. `Lorem`)
39
+ * `Faker-Method` is the method of that module (e.g. `word`)
40
+
41
+ The string after the `:` is basically "applied" to the [Faker](https://github.com/stympy/faker) module.
42
+ So `id:Number.positive` would actually call `Faker::Number.positive()` to
43
+ generate an `id`-field for one entry.
44
+
45
+ #### Other DEFs:
46
+
47
+ "id:Number.positive(5, 100)"
48
+ "text:Lorem.words(5)"
49
+ "created_at:Date.forward"
50
+
51
+ ### Usage Examples
52
+
53
+ faker-cli 50 "id:Number.positive"\
54
+ "filename:Lorem.words(2)"\
55
+ "filesize:Number.between(150, 700)"\
56
+ "created_at:Date.backward"\
57
+ "modified_at:Date.backward"\
58
+ "directory_id:Number.positive(2, 6)"
59
+
60
+ Will output a json array of 50 json objects that look like:
61
+
62
+ ```json
63
+ {
64
+ "id": 1136,
65
+ "filename": "rem necessitatibus",
66
+ "filesize": 300,
67
+ "directory_id": 4,
68
+ "created_at": "2013-09-25",
69
+ "modified_at": "2014-07-14"
70
+ }
71
+ ```
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it ( https://github.com/[my-github-username]/faker-cli/fork )
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'faker/cli'
4
+
5
+ Faker::Cli::run
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'faker/cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "faker-cli"
8
+ spec.version = Faker::Cli::VERSION
9
+ spec.authors = ["Tobias Witt"]
10
+ spec.email = ["tobias.witt@hhu.de"]
11
+ spec.summary = %q{Command line interface for the faker gem}
12
+ spec.description = %q{This tool helps to create a json array of json objects having certain fields and faked values in them.}
13
+ spec.homepage = "http://github.com/ohcibi/faker-cli"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "faker", "~> 1.4"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ end
@@ -0,0 +1,111 @@
1
+ require "faker/cli/version"
2
+
3
+ require 'pry'
4
+ require 'pry-byebug'
5
+ require 'json'
6
+ require 'faker'
7
+
8
+ require 'optparse'
9
+
10
+ module Faker
11
+ module Cli
12
+ class Field
13
+ attr_accessor :name, :type, :arguments
14
+
15
+ def initialize name, type, arguments
16
+ @name, @type = name, type
17
+ @arguments = arguments.map { |arg| Faker::Cli.int? arg }
18
+ end
19
+ end
20
+
21
+ class OptParse
22
+ DEFAULT_NUM = 10
23
+
24
+ class << self
25
+ attr_reader :parser
26
+ end
27
+
28
+ @@options = {}
29
+
30
+ @parser = OptionParser.new do |opts|
31
+ opts.banner = "Usage: #{$0} [options] DEF1 DEF2 ... DEFN"
32
+ opts.separator ""
33
+
34
+ opts.separator "Definitions:"
35
+
36
+ opts.separator ""
37
+ opts.separator "Options:"
38
+
39
+ opts.on "-n", "--num-entries [NUM]", Integer,
40
+ "Number of entries. Defaults to #{DEFAULT_NUM}" do |num|
41
+ @@options[:numentries] = num
42
+ end
43
+ end
44
+
45
+ def self.parse args
46
+ @parser.parse!(args)
47
+ @@options
48
+ end
49
+ end
50
+
51
+ def self.run
52
+ options = OptParse.parse ARGV
53
+ options[:numentries] = OptParse::DEFAULT_NUM unless options.has_key? :numentries
54
+
55
+ if ARGV.length < 1 then
56
+ puts OptParse::parser.help
57
+ exit
58
+ end
59
+
60
+ puts generate options
61
+ end
62
+
63
+ def self.make_fields
64
+ ARGV.map do |arg|
65
+ p = arg.split ":"
66
+ p << "Lorem.word" if p.length == 1
67
+
68
+ name = p[0]
69
+ type = p[1].match(/^[^\(\)]+/).to_s.split "."
70
+
71
+ argmatch = p[1].match(/\(([^\)]+)\)/)
72
+ args = []
73
+ args = argmatch[1].split(/,\s+/) if argmatch
74
+
75
+ Field.new(name, type, args)
76
+ end
77
+ end
78
+
79
+ def self.generate options
80
+ JSON.generate generate_result options[:numentries], make_fields
81
+ end
82
+
83
+ def self.generate_result num, fields
84
+ result = num.times.map do |n|
85
+ obj = {}
86
+
87
+ fields.each do |field|
88
+ faker_module = Faker.const_get field.type[0]
89
+ fake = faker_module.send(field.type[1], *field.arguments)
90
+ obj[field.name] = string? int? fake
91
+ end
92
+
93
+ obj
94
+ end
95
+ end
96
+
97
+ def self.int? arg
98
+ begin
99
+ arg = Integer arg
100
+ rescue ArgumentError, TypeError
101
+ end
102
+
103
+ arg
104
+ end
105
+
106
+ def self.string? arg
107
+ arg = arg.join " " if arg.is_a? Array
108
+ arg
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,5 @@
1
+ module Faker
2
+ module Cli
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faker-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tobias Witt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ description: This tool helps to create a json array of json objects having certain
42
+ fields and faked values in them.
43
+ email:
44
+ - tobias.witt@hhu.de
45
+ executables:
46
+ - faker-cli
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/faker-cli
56
+ - faker-cli.gemspec
57
+ - lib/faker/cli.rb
58
+ - lib/faker/cli/version.rb
59
+ homepage: http://github.com/ohcibi/faker-cli
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Command line interface for the faker gem
83
+ test_files: []