faker-bot 0.4.5 → 0.5.0

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: c0d9f5879fc71514770f70096568eddd9e69e61922ce46a3e63cbfd3310d7e85
4
- data.tar.gz: 91339a22891160fe23425c73d022e1545204608e0556179cb38c6677f8c9d197
3
+ metadata.gz: 4a409150c431509d7ccda5b95da8d39505da24b64f7d4d13a30674765750e266
4
+ data.tar.gz: 17ec8d367dff5cf0c089ec785ace9b909e7c6b4f3aaaaaacb24f3a9ef0f558cd
5
5
  SHA512:
6
- metadata.gz: 7ad7bdbc091932be9d3dd3d4767830e43c8abc9a49192787e7acecd673383dcd2c77c6db4824edcbc02595ab4b64174a054918b6bad7b60da06e4e18a48168b0
7
- data.tar.gz: 777a6b40d91aed4f13376e8aeb64197950fe963fcee7f7237e1c97c8076e1134d8feaef59441fe9b75f245a3b586234cb7141e5681d89c618a6aab8d3cf43518
6
+ metadata.gz: 02cccefaf2d42f27255be1b5d1212fdf95c7cd02ea043affe8d39e3e3f3aab6ab5b75c26a21a82e6a5dadf3af2c3b8c8b79e2132380257be3443e3c26bcef498
7
+ data.tar.gz: 252b837519d144f6cb8260c1dcec298cd847c3fce9af9338b99705fb4e7ad854b887d08b00b7ec94f053ea0c134f43a8e0a9f0d04af41b32119f74182b34b385
@@ -1 +1 @@
1
- 2.4.0
1
+ 2.5.3
@@ -0,0 +1,143 @@
1
+ # Change Log
2
+
3
+ ## [Unreleased](https://github.com/faker-ruby/faker-bot/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.4.5...HEAD)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Let `faker list` accept arguments [\#20](https://github.com/faker-ruby/faker-bot/issues/20)
10
+ - Allow list to accept filter and match on class name [\#39](https://github.com/faker-ruby/faker-bot/pull/39) ([bpleslie](https://github.com/bpleslie))
11
+ - Allow search to accept namespaces and partial matches [\#38](https://github.com/faker-ruby/faker-bot/pull/38) ([bpleslie](https://github.com/bpleslie))
12
+
13
+ **Fixed bugs:**
14
+
15
+ - Skip Faker Deprecation Warnings; The CLI handles that - II [\#33](https://github.com/faker-ruby/faker-bot/pull/33) ([akabiru](https://github.com/akabiru))
16
+
17
+ **Closed issues:**
18
+
19
+ - Fakerbot not searching namespace [\#36](https://github.com/faker-ruby/faker-bot/issues/36)
20
+
21
+ **Merged pull requests:**
22
+
23
+ - Add CI & QA Badges [\#34](https://github.com/faker-ruby/faker-bot/pull/34) ([akabiru](https://github.com/akabiru))
24
+ - Chore: CleanUp [\#32](https://github.com/faker-ruby/faker-bot/pull/32) ([akabiru](https://github.com/akabiru))
25
+
26
+ ## [v0.4.5](https://github.com/faker-ruby/faker-bot/tree/v0.4.5) (2019-07-11)
27
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.4.4...v0.4.5)
28
+
29
+ **Implemented enhancements:**
30
+
31
+ - faker-bot should be a separate gem [\#26](https://github.com/faker-ruby/faker-bot/issues/26)
32
+ - Gem name should be faker-bot [\#31](https://github.com/faker-ruby/faker-bot/pull/31) ([vbrazo](https://github.com/vbrazo))
33
+ - Distribute Faker::Reflector Responsibilities [\#22](https://github.com/faker-ruby/faker-bot/pull/22) ([akabiru](https://github.com/akabiru))
34
+
35
+ **Closed issues:**
36
+
37
+ - Integrate faker-bot in faker-ruby organization [\#27](https://github.com/faker-ruby/faker-bot/issues/27)
38
+ - Fix "NestedIterators" issue in lib/fakerbot/reflectors/search.rb [\#24](https://github.com/faker-ruby/faker-bot/issues/24)
39
+
40
+ **Merged pull requests:**
41
+
42
+ - Update README to republish faker-cli [\#29](https://github.com/faker-ruby/faker-bot/pull/29) ([vbrazo](https://github.com/vbrazo))
43
+ - chore: Rename from FakerBot to Faker::CLI [\#28](https://github.com/faker-ruby/faker-bot/pull/28) ([akabiru](https://github.com/akabiru))
44
+ - Add deprecation notes; thank you contributors! 🎉 [\#25](https://github.com/faker-ruby/faker-bot/pull/25) ([akabiru](https://github.com/akabiru))
45
+
46
+ ## [v0.4.4](https://github.com/faker-ruby/faker-bot/tree/v0.4.4) (2019-01-18)
47
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.4.3...v0.4.4)
48
+
49
+ **Implemented enhancements:**
50
+
51
+ - Add Unit tests for `FakerBot::Renderer` [\#11](https://github.com/faker-ruby/faker-bot/issues/11)
52
+
53
+ **Merged pull requests:**
54
+
55
+ - release v0.4.4 [\#21](https://github.com/faker-ruby/faker-bot/pull/21) ([akabiru](https://github.com/akabiru))
56
+ - Skip Gem::Deprecate Warnings; The CLI handles that [\#19](https://github.com/faker-ruby/faker-bot/pull/19) ([akabiru](https://github.com/akabiru))
57
+ - Touch Up Tests [\#18](https://github.com/faker-ruby/faker-bot/pull/18) ([akabiru](https://github.com/akabiru))
58
+ - chore\(workflow\): Add test runner for dev [\#17](https://github.com/faker-ruby/faker-bot/pull/17) ([akabiru](https://github.com/akabiru))
59
+ - Add CodeClimate [\#16](https://github.com/faker-ruby/faker-bot/pull/16) ([akabiru](https://github.com/akabiru))
60
+ - Update main.workflow [\#15](https://github.com/faker-ruby/faker-bot/pull/15) ([akabiru](https://github.com/akabiru))
61
+
62
+ ## [v0.4.3](https://github.com/faker-ruby/faker-bot/tree/v0.4.3) (2018-10-07)
63
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.4.2...v0.4.3)
64
+
65
+ **Implemented enhancements:**
66
+
67
+ - Improve Search [\#13](https://github.com/faker-ruby/faker-bot/issues/13)
68
+
69
+ **Merged pull requests:**
70
+
71
+ - Improve search functionality [\#14](https://github.com/faker-ruby/faker-bot/pull/14) ([codealchemy](https://github.com/codealchemy))
72
+
73
+ ## [v0.4.2](https://github.com/faker-ruby/faker-bot/tree/v0.4.2) (2018-10-04)
74
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.4.1...v0.4.2)
75
+
76
+ **Implemented enhancements:**
77
+
78
+ - Handle Deprecation Warnings [\#7](https://github.com/faker-ruby/faker-bot/issues/7)
79
+ - Sort `fakerbot list` alphabetically [\#4](https://github.com/faker-ruby/faker-bot/issues/4)
80
+
81
+ **Fixed bugs:**
82
+
83
+ - Handle Deprecation Warnings [\#7](https://github.com/faker-ruby/faker-bot/issues/7)
84
+
85
+ **Merged pull requests:**
86
+
87
+ - Support `search` for ruby less than 2.4.0 [\#12](https://github.com/faker-ruby/faker-bot/pull/12) ([kfpo](https://github.com/kfpo))
88
+
89
+ ## [v0.4.1](https://github.com/faker-ruby/faker-bot/tree/v0.4.1) (2018-09-18)
90
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.4.0...v0.4.1)
91
+
92
+ **Merged pull requests:**
93
+
94
+ - Handle Deprecation Warnings [\#10](https://github.com/faker-ruby/faker-bot/pull/10) ([shtakai](https://github.com/shtakai))
95
+
96
+ ## [v0.4.0](https://github.com/faker-ruby/faker-bot/tree/v0.4.0) (2018-08-13)
97
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.3.0...v0.4.0)
98
+
99
+ **Implemented enhancements:**
100
+
101
+ - Add flag to show sample faker output [\#5](https://github.com/faker-ruby/faker-bot/issues/5)
102
+
103
+ **Fixed bugs:**
104
+
105
+ - Only show public class methods [\#3](https://github.com/faker-ruby/faker-bot/issues/3)
106
+
107
+ **Merged pull requests:**
108
+
109
+ - Include Faker sample output [\#6](https://github.com/faker-ruby/faker-bot/pull/6) ([akabiru](https://github.com/akabiru))
110
+
111
+ ## [v0.3.0](https://github.com/faker-ruby/faker-bot/tree/v0.3.0) (2018-08-10)
112
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.2.4...v0.3.0)
113
+
114
+ **Merged pull requests:**
115
+
116
+ - Add `fakerbot list` Command [\#2](https://github.com/faker-ruby/faker-bot/pull/2) ([akabiru](https://github.com/akabiru))
117
+
118
+ ## [v0.2.4](https://github.com/faker-ruby/faker-bot/tree/v0.2.4) (2018-08-10)
119
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.2.3...v0.2.4)
120
+
121
+ ## [v0.2.3](https://github.com/faker-ruby/faker-bot/tree/v0.2.3) (2018-08-09)
122
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.2.1...v0.2.3)
123
+
124
+ ## [v0.2.1](https://github.com/faker-ruby/faker-bot/tree/v0.2.1) (2018-08-09)
125
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.2.0...v0.2.1)
126
+
127
+ ## [v0.2.0](https://github.com/faker-ruby/faker-bot/tree/v0.2.0) (2018-08-09)
128
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.1.2...v0.2.0)
129
+
130
+ ## [v0.1.2](https://github.com/faker-ruby/faker-bot/tree/v0.1.2) (2018-07-24)
131
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.1.1...v0.1.2)
132
+
133
+ ## [v0.1.1](https://github.com/faker-ruby/faker-bot/tree/v0.1.1) (2018-07-03)
134
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.1.0...v0.1.1)
135
+
136
+ ## [v0.1.0](https://github.com/faker-ruby/faker-bot/tree/v0.1.0) (2018-07-03)
137
+ **Merged pull requests:**
138
+
139
+ - Add Reflectors [\#1](https://github.com/faker-ruby/faker-bot/pull/1) ([akabiru](https://github.com/akabiru))
140
+
141
+
142
+
143
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faker-bot (0.4.5)
4
+ faker-bot (0.5.0)
5
5
  faker
6
6
  pastel (~> 0.7.2)
7
7
  thor (~> 0.20.0)
@@ -25,7 +25,7 @@ GEM
25
25
  domain_name (0.5.20190701)
26
26
  unf (>= 0.0.5, < 1.0.0)
27
27
  equatable (0.6.1)
28
- faker (1.9.6)
28
+ faker (2.0)
29
29
  i18n (>= 0.7)
30
30
  ffi (1.11.1)
31
31
  formatador (0.2.5)
data/Guardfile CHANGED
@@ -1,31 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # A sample Guardfile
4
3
  # 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
4
  #
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
5
  guard :rspec, cmd: 'bundle exec rspec' do
30
6
  require 'guard/rspec/dsl'
31
7
  dsl = Guard::RSpec::Dsl.new(self)
@@ -41,32 +17,4 @@ guard :rspec, cmd: 'bundle exec rspec' do
41
17
  # Ruby files
42
18
  ruby = dsl.ruby
43
19
  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
20
  end
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # faker-bot
2
2
 
3
+ [![Build Status](https://travis-ci.org/faker-ruby/faker-bot.svg?branch=master)](https://travis-ci.org/faker-ruby/faker-bot)
4
+ [![Gem Version](https://badge.fury.io/rb/faker-bot.svg)](https://badge.fury.io/rb/faker-bot)
5
+ [![Open Source Helpers](https://www.codetriage.com/faker-ruby/faker-bot/badges/users.svg)](https://www.codetriage.com/faker-ruby/faker-bot)
6
+
3
7
  > Quickly look up [Faker](https://github.com/stympy/faker) methods without leaving your terminal!
4
8
 
5
9
  ## Installation
@@ -10,42 +10,41 @@ module Faker
10
10
  module Bot
11
11
  class Base < Thor
12
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
13
 
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
14
+ desc 'version', 'Faker version'
15
+ def version
16
+ puts "v#{Faker::Bot::VERSION}"
17
+ end
18
+ map %w[--version -v] => :version
19
+
20
+ desc 'list', 'List all Faker constants'
21
+ method_option :help, aliases: '-h', type: :boolean,
22
+ desc: 'Display usage information'
23
+ method_option :show_methods, aliases: '-m', type: :boolean, default: true,
24
+ desc: 'Display Faker constants with methods'
25
+ method_option :verbose, aliases: '-v', type: :boolean,
26
+ desc: 'Include sample Faker output'
27
+ def list(filter = nil)
28
+ if options[:help]
29
+ invoke :help, ['list']
30
+ else
31
+ filter_options = options.merge(filter: filter)
32
+ Faker::Bot::Commands::List.new(filter_options).execute
34
33
  end
34
+ end
35
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
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)
49
48
  end
50
49
  end
51
50
  end
@@ -11,6 +11,19 @@ module Faker
11
11
  result = Reflectors::List.call(options)
12
12
  render(result, output)
13
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, that class doesn't exist 😢", "\n",
25
+ 'Try something like `Faker::Beer` or `Beer`.', "\n"
26
+ end
14
27
  end
15
28
  end
16
29
  end
@@ -11,6 +11,9 @@ module Faker
11
11
  #
12
12
  class Reflector
13
13
  Faker::Base.class_eval do
14
+ # Skip default deprecation warning output; the CLI will display that.
15
+ Gem::Deprecate.skip = true
16
+
14
17
  # Select `Faker` subclasses
15
18
  # @return [Array] `Faker::Base` sub classes
16
19
  def self.descendants
@@ -9,6 +9,7 @@ module Faker
9
9
  # @api private
10
10
  #
11
11
  class List < Reflector
12
+ attr_reader :filter
12
13
  attr_reader :show_methods
13
14
 
14
15
  def self.call(options)
@@ -16,22 +17,35 @@ module Faker
16
17
  end
17
18
 
18
19
  def initialize(options = {})
20
+ @filter = options[:filter]
19
21
  @show_methods = options[:show_methods]
20
22
 
21
23
  super
22
24
  end
23
25
 
24
26
  def call
25
- show_methods ? all_descendants_with_methods : faker_descendants
27
+ show_methods ? list_descendants_with_methods : list_descendants
26
28
  end
27
29
 
28
30
  private
29
31
 
30
- def all_descendants_with_methods
32
+ def list_descendants_with_methods
33
+ list_descendants
34
+ descendants_with_methods
35
+ end
36
+
37
+ def list_descendants
31
38
  faker_descendants.each do |descendant|
32
- store(descendant, descendant.my_singleton_methods)
39
+ if filter_matches_class_name?(descendant.to_s)
40
+ store(descendant, descendant.my_singleton_methods)
41
+ end
33
42
  end
34
- descendants_with_methods
43
+ descendants_with_methods.keys
44
+ end
45
+
46
+ def filter_matches_class_name?(class_name)
47
+ return true unless filter
48
+ class_name.match(/#{filter}/)
35
49
  end
36
50
  end
37
51
  end
@@ -16,7 +16,7 @@ module Faker
16
16
  end
17
17
 
18
18
  def initialize(query)
19
- @query = query
19
+ @query = query.downcase
20
20
 
21
21
  super
22
22
  end
@@ -31,14 +31,20 @@ module Faker
31
31
  def search_descendants_matching_query
32
32
  faker_descendants.each do |descendant|
33
33
  methods = descendant.my_singleton_methods
34
- matching = methods.select { |method| query_matches?(method.to_s) }
35
- store(descendant, matching)
34
+ if query_matches_class_name?(descendant.to_s)
35
+ store(descendant, methods)
36
+ else
37
+ store(descendant, methods.select { |method| query_matches_method?(method.to_s) })
38
+ end
36
39
  end
37
40
  end
38
41
 
39
- def query_matches?(method_name)
40
- method_name_parts = method_name.split(/_/).reject(&:empty?)
41
- query.match(/#{method_name_parts.join('|')}/)
42
+ def query_matches_method?(method_name)
43
+ method_name.match(/#{query}/)
44
+ end
45
+
46
+ def query_matches_class_name?(class_name)
47
+ class_name.downcase.match(/#{query}/)
42
48
  end
43
49
  end
44
50
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faker
4
4
  module Bot
5
- VERSION = '0.4.5'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faker-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Kabiru
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-09 00:00:00.000000000 Z
11
+ date: 2019-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker
@@ -206,6 +206,7 @@ files:
206
206
  - ".rubocop.yml"
207
207
  - ".ruby-version"
208
208
  - ".travis.yml"
209
+ - CHANGELOG.md
209
210
  - CODE_OF_CONDUCT.md
210
211
  - Gemfile
211
212
  - Gemfile.lock
@@ -217,7 +218,6 @@ files:
217
218
  - bin/faker
218
219
  - bin/setup
219
220
  - faker-bot.gemspec
220
- - faker-cli-0.4.5.gem
221
221
  - lib/faker-bot.rb
222
222
  - lib/faker/bot.rb
223
223
  - lib/faker/bot/command.rb
@@ -228,7 +228,6 @@ files:
228
228
  - lib/faker/bot/reflectors/search.rb
229
229
  - lib/faker/bot/renderer.rb
230
230
  - lib/faker/bot/version.rb
231
- - lib/faker/renderer.rb
232
231
  homepage: https://github.com/faker-ruby/faker-bot
233
232
  licenses:
234
233
  - MIT
@@ -249,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
248
  version: '0'
250
249
  requirements: []
251
250
  rubyforge_project:
252
- rubygems_version: 2.7.9
251
+ rubygems_version: 2.7.6
253
252
  signing_key:
254
253
  specification_version: 4
255
254
  summary: A stympy/faker lookup command line tool.
Binary file
@@ -1,91 +0,0 @@
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