faker-bot 0.4.5

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
+ SHA256:
3
+ metadata.gz: c0d9f5879fc71514770f70096568eddd9e69e61922ce46a3e63cbfd3310d7e85
4
+ data.tar.gz: 91339a22891160fe23425c73d022e1545204608e0556179cb38c6677f8c9d197
5
+ SHA512:
6
+ metadata.gz: 7ad7bdbc091932be9d3dd3d4767830e43c8abc9a49192787e7acecd673383dcd2c77c6db4824edcbc02595ab4b64174a054918b6bad7b60da06e4e18a48168b0
7
+ data.tar.gz: 777a6b40d91aed4f13376e8aeb64197950fe963fcee7f7237e1c97c8076e1134d8feaef59441fe9b75f245a3b586234cb7141e5681d89c618a6aab8d3cf43518
@@ -0,0 +1,9 @@
1
+ workflow "on pull request merge, delete the branch" {
2
+ on = "pull_request"
3
+ resolves = ["branch cleanup"]
4
+ }
5
+
6
+ action "branch cleanup" {
7
+ uses = "jessfraz/branch-cleanup-action@master"
8
+ secrets = ["GITHUB_TOKEN"]
9
+ }
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,12 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "Gemfile"
4
+ - "*.gemspec"
5
+ - "spec/spec_helper.rb"
6
+ - "config/**/*"
7
+ UseCache: false
8
+ Style/Documentation:
9
+ Exclude:
10
+ - "lib/**/*"
11
+ Metrics/ModuleLength:
12
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.4.0
@@ -0,0 +1,14 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=30c01e786e457860ad57c4d3ecc629c67b08510b170d86764eb360ffd5f7d8db
4
+ language: ruby
5
+ rvm:
6
+ - 2.4
7
+ before_script:
8
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
+ - chmod +x ./cc-test-reporter
10
+ - ./cc-test-reporter before-build
11
+ script:
12
+ - bundle exec rspec
13
+ after_script:
14
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at austin.kabiru@andela.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in faker-cli.gemspec
6
+ gemspec
@@ -0,0 +1,137 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ faker-bot (0.4.5)
5
+ faker
6
+ pastel (~> 0.7.2)
7
+ thor (~> 0.20.0)
8
+ tty-pager
9
+ tty-screen
10
+ tty-tree
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ coderay (1.1.2)
16
+ concurrent-ruby (1.1.5)
17
+ coveralls (0.7.1)
18
+ multi_json (~> 1.3)
19
+ rest-client
20
+ simplecov (>= 0.7)
21
+ term-ansicolor
22
+ thor
23
+ diff-lcs (1.3)
24
+ docile (1.3.2)
25
+ domain_name (0.5.20190701)
26
+ unf (>= 0.0.5, < 1.0.0)
27
+ equatable (0.6.1)
28
+ faker (1.9.6)
29
+ i18n (>= 0.7)
30
+ ffi (1.11.1)
31
+ formatador (0.2.5)
32
+ guard (2.15.0)
33
+ formatador (>= 0.2.4)
34
+ listen (>= 2.7, < 4.0)
35
+ lumberjack (>= 1.0.12, < 2.0)
36
+ nenv (~> 0.1)
37
+ notiffany (~> 0.0)
38
+ pry (>= 0.9.12)
39
+ shellany (~> 0.0)
40
+ thor (>= 0.18.1)
41
+ guard-compat (1.2.1)
42
+ guard-rspec (4.7.3)
43
+ guard (~> 2.1)
44
+ guard-compat (~> 1.1)
45
+ rspec (>= 2.99.0, < 4.0)
46
+ http-cookie (1.0.3)
47
+ domain_name (~> 0.5)
48
+ i18n (1.6.0)
49
+ concurrent-ruby (~> 1.0)
50
+ json (2.2.0)
51
+ listen (3.1.5)
52
+ rb-fsevent (~> 0.9, >= 0.9.4)
53
+ rb-inotify (~> 0.9, >= 0.9.7)
54
+ ruby_dep (~> 1.2)
55
+ lumberjack (1.0.13)
56
+ method_source (0.9.2)
57
+ mime-types (3.2.2)
58
+ mime-types-data (~> 3.2015)
59
+ mime-types-data (3.2019.0331)
60
+ multi_json (1.13.1)
61
+ nenv (0.3.0)
62
+ netrc (0.11.0)
63
+ notiffany (0.1.1)
64
+ nenv (~> 0.1)
65
+ shellany (~> 0.0)
66
+ pastel (0.7.3)
67
+ equatable (~> 0.6)
68
+ tty-color (~> 0.5)
69
+ pry (0.12.2)
70
+ coderay (~> 1.1.0)
71
+ method_source (~> 0.9.0)
72
+ rake (10.5.0)
73
+ rb-fsevent (0.10.3)
74
+ rb-inotify (0.10.0)
75
+ ffi (~> 1.0)
76
+ rest-client (2.0.2)
77
+ http-cookie (>= 1.0.2, < 2.0)
78
+ mime-types (>= 1.16, < 4.0)
79
+ netrc (~> 0.8)
80
+ rspec (3.8.0)
81
+ rspec-core (~> 3.8.0)
82
+ rspec-expectations (~> 3.8.0)
83
+ rspec-mocks (~> 3.8.0)
84
+ rspec-core (3.8.2)
85
+ rspec-support (~> 3.8.0)
86
+ rspec-expectations (3.8.4)
87
+ diff-lcs (>= 1.2.0, < 2.0)
88
+ rspec-support (~> 3.8.0)
89
+ rspec-mocks (3.8.1)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.8.0)
92
+ rspec-support (3.8.2)
93
+ ruby_dep (1.5.0)
94
+ shellany (0.0.1)
95
+ simplecov (0.17.0)
96
+ docile (~> 1.1)
97
+ json (>= 1.8, < 3)
98
+ simplecov-html (~> 0.10.0)
99
+ simplecov-html (0.10.2)
100
+ strings (0.1.5)
101
+ strings-ansi (~> 0.1)
102
+ unicode-display_width (~> 1.5)
103
+ unicode_utils (~> 1.4)
104
+ strings-ansi (0.1.0)
105
+ term-ansicolor (1.7.1)
106
+ tins (~> 1.0)
107
+ thor (0.20.3)
108
+ tins (1.21.0)
109
+ tty-color (0.5.0)
110
+ tty-pager (0.12.1)
111
+ strings (~> 0.1.4)
112
+ tty-screen (~> 0.6)
113
+ tty-which (~> 0.4)
114
+ tty-screen (0.7.0)
115
+ tty-tree (0.3.0)
116
+ tty-which (0.4.1)
117
+ unf (0.1.4)
118
+ unf_ext
119
+ unf_ext (0.0.7.6)
120
+ unicode-display_width (1.6.0)
121
+ unicode_utils (1.4.0)
122
+
123
+ PLATFORMS
124
+ ruby
125
+
126
+ DEPENDENCIES
127
+ bundler (>= 1.16)
128
+ coveralls
129
+ faker-bot!
130
+ guard-rspec
131
+ pry
132
+ rake (~> 10.0)
133
+ rspec (~> 3.0)
134
+ simplecov (~> 0.12)
135
+
136
+ BUNDLED WITH
137
+ 2.0.2
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sample Guardfile
4
+ # More info at https://github.com/guard/guard#readme
5
+
6
+ ## Uncomment and set this to only include directories you want to watch
7
+ # directories %w(app lib config test spec features) \
8
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
9
+
10
+ ## Note: if you are using the `directories` clause above and you are not
11
+ ## watching the project directory ('.'), then you will want to move
12
+ ## the Guardfile to a watched dir and symlink it back, e.g.
13
+ #
14
+ # $ mkdir config
15
+ # $ mv Guardfile config/
16
+ # $ ln -s config/Guardfile .
17
+ #
18
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19
+
20
+ # Note: The cmd option is now required due to the increasing number of ways
21
+ # rspec may be run, below are examples of the most common uses.
22
+ # * bundler: 'bundle exec rspec'
23
+ # * bundler binstubs: 'bin/rspec'
24
+ # * spring: 'bin/rspec' (This will use spring if running and you have
25
+ # installed the spring binstubs per the docs)
26
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
27
+ # * 'just' rspec: 'rspec'
28
+
29
+ guard :rspec, cmd: 'bundle exec rspec' do
30
+ require 'guard/rspec/dsl'
31
+ dsl = Guard::RSpec::Dsl.new(self)
32
+
33
+ # Feel free to open issues for suggestions and improvements
34
+
35
+ # RSpec files
36
+ rspec = dsl.rspec
37
+ watch(rspec.spec_helper) { rspec.spec_dir }
38
+ watch(rspec.spec_support) { rspec.spec_dir }
39
+ watch(rspec.spec_files)
40
+
41
+ # Ruby files
42
+ ruby = dsl.ruby
43
+ dsl.watch_spec_files_for(ruby.lib_files)
44
+
45
+ # Rails files
46
+ rails = dsl.rails(view_extensions: %w[erb haml slim])
47
+ dsl.watch_spec_files_for(rails.app_files)
48
+ dsl.watch_spec_files_for(rails.views)
49
+
50
+ watch(rails.controllers) do |m|
51
+ [
52
+ rspec.spec.call("routing/#{m[1]}_routing"),
53
+ rspec.spec.call("controllers/#{m[1]}_controller"),
54
+ rspec.spec.call("acceptance/#{m[1]}")
55
+ ]
56
+ end
57
+
58
+ # Rails config changes
59
+ watch(rails.spec_helper) { rspec.spec_dir }
60
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
61
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
62
+
63
+ # Capybara features specs
64
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
65
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
66
+
67
+ # Turnip features and steps
68
+ watch(%r{^spec/acceptance/(.+)\.feature$})
69
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
70
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
71
+ end
72
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Austin Kabiru
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.
@@ -0,0 +1,85 @@
1
+ # faker-bot
2
+
3
+ > Quickly look up [Faker](https://github.com/stympy/faker) methods without leaving your terminal!
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ gem install faker-bot
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ 1.) Run a quick lookup
14
+
15
+ ```bash
16
+ $ faker search name
17
+ # Faker::SwordArtOnline
18
+ # └── real_name
19
+ # └── game_name
20
+ # Faker::Superhero
21
+ # └── name
22
+ # ....
23
+ ```
24
+
25
+ 2.) List methods
26
+
27
+ ```sh
28
+ $ faker list
29
+ # Faker::BackToTheFuture
30
+ # ├── quote
31
+ # ├── date
32
+ # └── character
33
+ # Faker::Finance
34
+ # └── credit_card
35
+ # ....
36
+ ```
37
+
38
+ `faker` also includes an option to display sample output via the `--verbose` or `-v` flag. :wink:
39
+
40
+ 3.)
41
+
42
+ ```sh
43
+ $ faker list -v
44
+ # Faker::Appliance
45
+ # ├── brand=> Whirlpool
46
+ # └── equipment=> Sump pump
47
+ # Faker::UmphreysMcgee
48
+ # └── song=> Headphones & Snowcones
49
+ $ faker search name -v
50
+ # Faker::App
51
+ # └── name=> Subin
52
+ # Faker::Address
53
+ # └── street_name=> Percy Landing
54
+ # ....
55
+ ```
56
+
57
+ ## New Features! :sunglasses: :dancers:
58
+
59
+ - [x] List classes with methods E.g. Faker::FunnyName should list `.name`,`.first_name` e.t.c.
60
+ - [x] Expand search to Faker::Base sub classes
61
+ - [x] Paginate results :book:
62
+
63
+ ![screen shot 2018-08-13 at 23 33 51](https://user-images.githubusercontent.com/17295175/44056603-6343f9f2-9f51-11e8-933d-55367e25be35.jpg)
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ 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).
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/faker-ruby/faker-bot. 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.
74
+
75
+ ## Credits
76
+
77
+ Terminal awesomeness made easy by the [TTY Toolkit](http://piotrmurach.github.io/tty/). :beer:
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
82
+
83
+ ## Code of Conduct
84
+
85
+ Everyone interacting in the faker-bot project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/faker-ruby/faker-bot/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'faker/bot'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require 'pry'
12
+ Pry.start
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib_path = File.expand_path('../lib', __dir__)
5
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
6
+ require 'faker/bot'
7
+
8
+ Signal.trap('INT') do
9
+ warn("\n#{caller.join("\n")}: interrupted")
10
+ exit(1)
11
+ end
12
+
13
+ begin
14
+ Faker::Bot::Base.start
15
+ rescue Faker::Bot::Base::Error => e
16
+ puts "ERROR: #{e.message}"
17
+ exit 1
18
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "faker/bot/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "faker-bot"
8
+ spec.version = Faker::Bot::VERSION
9
+ spec.authors = ["Austin Kabiru"]
10
+ spec.email = ["makabby@gmail.com"]
11
+
12
+ spec.summary = %q{A stympy/faker lookup command line tool.}
13
+ spec.description = %q{Quickly look up Faker methods without leaving your terminal!}
14
+ spec.homepage = "https://github.com/faker-ruby/faker-bot"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'bin'
19
+ spec.executables = ['faker']
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency "faker"
23
+ spec.add_dependency "pastel", "~> 0.7.2"
24
+ spec.add_dependency "thor", "~> 0.20.0"
25
+ spec.add_dependency "tty-pager"
26
+ spec.add_dependency "tty-screen"
27
+ spec.add_dependency "tty-tree"
28
+
29
+ spec.add_development_dependency "bundler", ">= 1.16"
30
+ spec.add_development_dependency "coveralls"
31
+ spec.add_development_dependency "guard-rspec"
32
+ spec.add_development_dependency "pry"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "simplecov", "~> 0.12"
36
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'faker/bot'
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ require 'faker/bot/commands/list'
6
+ require 'faker/bot/commands/search'
7
+ require 'faker/bot/version'
8
+
9
+ module Faker
10
+ module Bot
11
+ class Base < Thor
12
+ Error = Class.new(StandardError)
13
+ # Skip default deprecation warning output; the Bot will display that.
14
+ Gem::Deprecate.skip_during do
15
+ desc 'version', 'Faker version'
16
+ def version
17
+ puts "v#{Faker::Bot::VERSION}"
18
+ end
19
+ map %w[--version -v] => :version
20
+
21
+ desc 'list', 'List all Faker constants'
22
+ method_option :help, aliases: '-h', type: :boolean,
23
+ desc: 'Display usage information'
24
+ method_option :show_methods, aliases: '-m', type: :boolean, default: true,
25
+ desc: 'Display Faker constants with methods'
26
+ method_option :verbose, aliases: '-v', type: :boolean,
27
+ desc: 'Include sample Faker output'
28
+ def list(*)
29
+ if options[:help]
30
+ invoke :help, ['list']
31
+ else
32
+ Faker::Bot::Commands::List.new(options).execute
33
+ end
34
+ end
35
+
36
+ desc 'search [Faker]', 'Search Faker method(s)'
37
+ method_option :help, aliases: '-h', type: :boolean,
38
+ desc: 'Display usage information'
39
+ method_option :show_methods, aliases: '-m', type: :boolean, default: true,
40
+ desc: 'Display Faker constants with methods'
41
+ method_option :verbose, aliases: '-v', type: :boolean,
42
+ desc: 'Include sample Faker output'
43
+ def search(query)
44
+ if options[:help]
45
+ invoke :help, ['search']
46
+ else
47
+ Faker::Bot::Commands::Search.new(options).execute(query)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ require_relative 'renderer'
6
+
7
+ module Faker
8
+ module Bot
9
+ class Command
10
+ extend Forwardable
11
+
12
+ def_delegators :command, :run
13
+ attr_reader :options
14
+
15
+ def initialize(options)
16
+ @options = options
17
+ end
18
+
19
+ def render(result, output)
20
+ Renderer.call(result, options, output)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../command'
4
+ require_relative '../reflectors/list'
5
+
6
+ module Faker
7
+ module Bot
8
+ module Commands
9
+ class List < Command
10
+ def execute(output: $stdout)
11
+ result = Reflectors::List.call(options)
12
+ render(result, output)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../command'
4
+ require_relative '../reflectors/search'
5
+
6
+ module Faker
7
+ module Bot
8
+ module Commands
9
+ class Search < Command
10
+ def execute(input, output: $stdout)
11
+ result = Reflectors::Search.call(input)
12
+ render(result, output)
13
+ end
14
+
15
+ private
16
+
17
+ def render(result, output)
18
+ return not_found(output) if result.empty?
19
+
20
+ super(result, output)
21
+ end
22
+
23
+ def not_found(output)
24
+ output.puts "\nSorry, we couldn't find a match 😢", "\n"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faker'
4
+
5
+ module Faker
6
+ module Bot
7
+ # Abstract `Faker` Reflector - introspects the `Faker` module
8
+ #
9
+ # @api private
10
+ # @abstract
11
+ #
12
+ class Reflector
13
+ Faker::Base.class_eval do
14
+ # Select `Faker` subclasses
15
+ # @return [Array] `Faker::Base` sub classes
16
+ def self.descendants
17
+ @descendants ||= ObjectSpace.each_object(Class).select do |klass|
18
+ klass < self
19
+ end
20
+ end
21
+
22
+ # Select public class methods
23
+ # @return [Array] public methods
24
+ def self.my_singleton_methods
25
+ singleton_methods(false).select { |m| respond_to?(m) }
26
+ end
27
+ end
28
+
29
+ attr_reader :descendants_with_methods
30
+
31
+ def initialize(*)
32
+ @descendants_with_methods = Hash.new { |h, k| h[k] = [] }
33
+ end
34
+
35
+ protected
36
+
37
+ def store(descendant, methods)
38
+ return if methods.empty?
39
+
40
+ descendants_with_methods[descendant].concat(methods)
41
+ end
42
+
43
+ def faker_descendants
44
+ @faker_descendants ||= Faker::Base.descendants
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../reflector'
4
+
5
+ module Faker
6
+ module Bot
7
+ module Reflectors
8
+ # List command reflector
9
+ # @api private
10
+ #
11
+ class List < Reflector
12
+ attr_reader :show_methods
13
+
14
+ def self.call(options)
15
+ new(options).call
16
+ end
17
+
18
+ def initialize(options = {})
19
+ @show_methods = options[:show_methods]
20
+
21
+ super
22
+ end
23
+
24
+ def call
25
+ show_methods ? all_descendants_with_methods : faker_descendants
26
+ end
27
+
28
+ private
29
+
30
+ def all_descendants_with_methods
31
+ faker_descendants.each do |descendant|
32
+ store(descendant, descendant.my_singleton_methods)
33
+ end
34
+ descendants_with_methods
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../reflector'
4
+
5
+ module Faker
6
+ module Bot
7
+ module Reflectors
8
+ # Find command reflector
9
+ # @api private
10
+ #
11
+ class Search < Reflector
12
+ attr_reader :query
13
+
14
+ def self.call(query)
15
+ new(query).call
16
+ end
17
+
18
+ def initialize(query)
19
+ @query = query
20
+
21
+ super
22
+ end
23
+
24
+ def call
25
+ search_descendants_matching_query
26
+ descendants_with_methods
27
+ end
28
+
29
+ private
30
+
31
+ def search_descendants_matching_query
32
+ faker_descendants.each do |descendant|
33
+ methods = descendant.my_singleton_methods
34
+ matching = methods.select { |method| query_matches?(method.to_s) }
35
+ store(descendant, matching)
36
+ end
37
+ end
38
+
39
+ def query_matches?(method_name)
40
+ method_name_parts = method_name.split(/_/).reject(&:empty?)
41
+ query.match(/#{method_name_parts.join('|')}/)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pastel'
4
+ require 'tty/pager'
5
+ require 'tty/screen'
6
+ require 'tty/tree'
7
+
8
+ module Faker
9
+ module Bot
10
+ class Renderer
11
+ attr_reader :crayon, :hash, :options, :output, :pager
12
+
13
+ def self.call(*args)
14
+ new(*args).call
15
+ end
16
+
17
+ def initialize(hash, options, output)
18
+ @hash = hash
19
+ @options = options
20
+ @output = output
21
+ @crayon = Pastel.new(enabled: output.tty?)
22
+ @pager = TTY::Pager.new(command: 'less -R')
23
+ end
24
+
25
+ def call
26
+ if paginable?
27
+ pager.page(render)
28
+ else
29
+ output.puts(render)
30
+ end
31
+ end
32
+
33
+ def render
34
+ tree.render
35
+ end
36
+
37
+ def tree
38
+ @tree ||= TTY::Tree.new(build_tree)
39
+ end
40
+
41
+ def paginable?
42
+ gt_screen_height? && output.tty?
43
+ end
44
+
45
+ def gt_screen_height?
46
+ tree.nodes.size > TTY::Screen.height
47
+ end
48
+
49
+ private
50
+
51
+ def build_tree
52
+ results = hash.reduce({}) do |h, (const, methods)|
53
+ h.merge! node(const, methods&.sort)
54
+ end
55
+
56
+ results.sort_by(&:to_s).to_h
57
+ end
58
+
59
+ def node(const, methods)
60
+ {
61
+ crayon.green(const.to_s) => leaf(const, methods)
62
+ }
63
+ end
64
+
65
+ def leaf(const, methods)
66
+ (methods || []).map { |m| crayon.cyan(*leaf_args(m, const)) }
67
+ end
68
+
69
+ def leaf_args(method, const)
70
+ [method.to_s].tap { |arr| verbose_output(method, const, arr) if verbose? }
71
+ end
72
+
73
+ def verbose?
74
+ options[:verbose]
75
+ end
76
+
77
+ def verbose_output(method, const, arr)
78
+ fake, message = faker_method(method, const)
79
+ arr << crayon.dim.white("=> #{fake}") << crayon.dim.magenta.bold(message.to_s)
80
+ end
81
+
82
+ def faker_method(method, const)
83
+ [const.public_send(method), ensure_method_is_supported(method, const)]
84
+ rescue ArgumentError => _e
85
+ ['N/A', '']
86
+ end
87
+
88
+ def ensure_method_is_supported(method, const)
89
+ const.respond_to?(:"_deprecated_#{method}") ? ' ( WILL BE DEPRECATED )' : ''
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ module Bot
5
+ VERSION = '0.4.5'
6
+ end
7
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pastel'
4
+ require 'tty/pager'
5
+ require 'tty/screen'
6
+ require 'tty/tree'
7
+
8
+ module Faker::Bot
9
+ class Renderer
10
+ attr_reader :crayon, :hash, :options, :output, :pager
11
+
12
+ def self.call(*args)
13
+ new(*args).call
14
+ end
15
+
16
+ def initialize(hash, options, output)
17
+ @hash = hash
18
+ @options = options
19
+ @output = output
20
+ @crayon = Pastel.new(enabled: output.tty?)
21
+ @pager = TTY::Pager.new(command: 'less -R')
22
+ end
23
+
24
+ def call
25
+ if paginable?
26
+ pager.page(render)
27
+ else
28
+ output.puts(render)
29
+ end
30
+ end
31
+
32
+ def render
33
+ tree.render
34
+ end
35
+
36
+ def tree
37
+ @tree ||= TTY::Tree.new(build_tree)
38
+ end
39
+
40
+ def paginable?
41
+ gt_screen_height? && output.tty?
42
+ end
43
+
44
+ def gt_screen_height?
45
+ tree.nodes.size > TTY::Screen.height
46
+ end
47
+
48
+ private
49
+
50
+ def build_tree
51
+ result = hash.reduce({}) do |h, (faker, methods)|
52
+ h.merge! node(faker, methods&.sort)
53
+ end
54
+
55
+ result.sort_by(&:to_s).to_h
56
+ end
57
+
58
+ def node(const, methods)
59
+ {
60
+ crayon.green(const.to_s) => leaf(const, methods)
61
+ }
62
+ end
63
+
64
+ def leaf(const, methods)
65
+ (methods || []).map { |m| crayon.cyan(*leaf_args(m, const)) }
66
+ end
67
+
68
+ def leaf_args(method, const)
69
+ [method.to_s].tap { |arr| verbose_output(method, const, arr) if verbose? }
70
+ end
71
+
72
+ def verbose?
73
+ options[:verbose]
74
+ end
75
+
76
+ def verbose_output(method, const, arr)
77
+ fake, message = faker_method(method, const)
78
+ arr << crayon.dim.white("=> #{fake}") << crayon.dim.magenta.bold(message.to_s)
79
+ end
80
+
81
+ def faker_method(method, const)
82
+ [const.public_send(method), ensure_method_is_supported(method, const)]
83
+ rescue ArgumentError => _e
84
+ ['N/A', '']
85
+ end
86
+
87
+ def ensure_method_is_supported(method, const)
88
+ const.respond_to?(:"_deprecated_#{method}") ? ' ( WILL BE DEPRECATED )' : ''
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,256 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faker-bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.5
5
+ platform: ruby
6
+ authors:
7
+ - Austin Kabiru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-09 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pastel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.20.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.20.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-pager
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: tty-screen
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tty-tree
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '1.16'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '1.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '10.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '10.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '3.0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '3.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.12'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.12'
195
+ description: Quickly look up Faker methods without leaving your terminal!
196
+ email:
197
+ - makabby@gmail.com
198
+ executables:
199
+ - faker
200
+ extensions: []
201
+ extra_rdoc_files: []
202
+ files:
203
+ - ".github/main.workflow"
204
+ - ".gitignore"
205
+ - ".rspec"
206
+ - ".rubocop.yml"
207
+ - ".ruby-version"
208
+ - ".travis.yml"
209
+ - CODE_OF_CONDUCT.md
210
+ - Gemfile
211
+ - Gemfile.lock
212
+ - Guardfile
213
+ - LICENSE.txt
214
+ - README.md
215
+ - Rakefile
216
+ - bin/console
217
+ - bin/faker
218
+ - bin/setup
219
+ - faker-bot.gemspec
220
+ - faker-cli-0.4.5.gem
221
+ - lib/faker-bot.rb
222
+ - lib/faker/bot.rb
223
+ - lib/faker/bot/command.rb
224
+ - lib/faker/bot/commands/list.rb
225
+ - lib/faker/bot/commands/search.rb
226
+ - lib/faker/bot/reflector.rb
227
+ - lib/faker/bot/reflectors/list.rb
228
+ - lib/faker/bot/reflectors/search.rb
229
+ - lib/faker/bot/renderer.rb
230
+ - lib/faker/bot/version.rb
231
+ - lib/faker/renderer.rb
232
+ homepage: https://github.com/faker-ruby/faker-bot
233
+ licenses:
234
+ - MIT
235
+ metadata: {}
236
+ post_install_message:
237
+ rdoc_options: []
238
+ require_paths:
239
+ - lib
240
+ required_ruby_version: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - ">="
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ required_rubygems_version: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - ">="
248
+ - !ruby/object:Gem::Version
249
+ version: '0'
250
+ requirements: []
251
+ rubyforge_project:
252
+ rubygems_version: 2.7.9
253
+ signing_key:
254
+ specification_version: 4
255
+ summary: A stympy/faker lookup command line tool.
256
+ test_files: []