faker-bot 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a409150c431509d7ccda5b95da8d39505da24b64f7d4d13a30674765750e266
4
- data.tar.gz: 17ec8d367dff5cf0c089ec785ace9b909e7c6b4f3aaaaaacb24f3a9ef0f558cd
3
+ metadata.gz: e7fdf014f0c352744056c5ae4c197f99e204e8924e33a0f3ceb9e9b9d9d85b40
4
+ data.tar.gz: 3b7b462bdfa2ff3668340a70ac4ec7647dcc15d3b4f853d5381f2083f5b48841
5
5
  SHA512:
6
- metadata.gz: 02cccefaf2d42f27255be1b5d1212fdf95c7cd02ea043affe8d39e3e3f3aab6ab5b75c26a21a82e6a5dadf3af2c3b8c8b79e2132380257be3443e3c26bcef498
7
- data.tar.gz: 252b837519d144f6cb8260c1dcec298cd847c3fce9af9338b99705fb4e7ad854b887d08b00b7ec94f053ea0c134f43a8e0a9f0d04af41b32119f74182b34b385
6
+ metadata.gz: 99fbcbf1c3e43bfe6f0dc2edd10e65e2978f1bee35ee938e9d1b1ad24dcb83a7139a6a03700b6ae357083fc49749c2855c3001ac5437025854871a5e3c3384f7
7
+ data.tar.gz: 5f6b448c79c65eaad1cfab9c9b1e6c2b4a863136bca3ae54bed317e9445e729798329df3c8e7edb5ae82f6afdf2fde189fcea0e1ebdbbf504ed37ed6cf68d724
@@ -0,0 +1,21 @@
1
+
2
+ version: "2"
3
+ plugins:
4
+ bundler-audit:
5
+ enabled: true
6
+ fixme:
7
+ enabled: true
8
+ flog:
9
+ enabled: true
10
+ reek:
11
+ enabled: true
12
+ rubocop:
13
+ enabled: true
14
+ exclude_patterns:
15
+ - "spec/"
16
+ - "vendor/"
17
+ - "Guardfile"
18
+ - "Rakefile"
19
+ - "bin/**/*"
20
+ - "config/**/*.rb"
21
+ - "script/**/*"
@@ -1,6 +1,6 @@
1
1
  env:
2
2
  global:
3
- - CC_TEST_REPORTER_ID=30c01e786e457860ad57c4d3ecc629c67b08510b170d86764eb360ffd5f7d8db
3
+ - CC_TEST_REPORTER_ID=97ada6a78eeebe77dc11dacfb31238d8c5c3ba39ccae8dec76279e8176221da5
4
4
  language: ruby
5
5
  rvm:
6
6
  - 2.4
@@ -2,7 +2,25 @@
2
2
 
3
3
  ## [Unreleased](https://github.com/faker-ruby/faker-bot/tree/HEAD)
4
4
 
5
- [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.4.5...HEAD)
5
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.5.0...HEAD)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Add Asciinema Demo [\#43](https://github.com/faker-ruby/faker-bot/pull/43) ([akabiru](https://github.com/akabiru))
10
+
11
+ **Closed issues:**
12
+
13
+ - Migrate FakerBot CI & QA integrations [\#30](https://github.com/faker-ruby/faker-bot/issues/30)
14
+
15
+ **Merged pull requests:**
16
+
17
+ - Fix gemspec summary [\#45](https://github.com/faker-ruby/faker-bot/pull/45) ([vbrazo](https://github.com/vbrazo))
18
+ - fix: Remove brakeman plugin; it's Rails specific [\#44](https://github.com/faker-ruby/faker-bot/pull/44) ([akabiru](https://github.com/akabiru))
19
+ - Add CodeClimate Configuration [\#42](https://github.com/faker-ruby/faker-bot/pull/42) ([akabiru](https://github.com/akabiru))
20
+ - chore\(docs\): Add Code Level YARD Documentation 📖 [\#35](https://github.com/faker-ruby/faker-bot/pull/35) ([akabiru](https://github.com/akabiru))
21
+
22
+ ## [v0.5.0](https://github.com/faker-ruby/faker-bot/tree/v0.5.0) (2019-07-31)
23
+ [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.4.5...v0.5.0)
6
24
 
7
25
  **Implemented enhancements:**
8
26
 
@@ -20,8 +38,10 @@
20
38
 
21
39
  **Merged pull requests:**
22
40
 
41
+ - Release v0.5.0 [\#41](https://github.com/faker-ruby/faker-bot/pull/41) ([akabiru](https://github.com/akabiru))
23
42
  - Add CI & QA Badges [\#34](https://github.com/faker-ruby/faker-bot/pull/34) ([akabiru](https://github.com/akabiru))
24
43
  - Chore: CleanUp [\#32](https://github.com/faker-ruby/faker-bot/pull/32) ([akabiru](https://github.com/akabiru))
44
+ - Update README to republish faker-cli [\#29](https://github.com/faker-ruby/faker-bot/pull/29) ([vbrazo](https://github.com/vbrazo))
25
45
 
26
46
  ## [v0.4.5](https://github.com/faker-ruby/faker-bot/tree/v0.4.5) (2019-07-11)
27
47
  [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.4.4...v0.4.5)
@@ -39,7 +59,6 @@
39
59
 
40
60
  **Merged pull requests:**
41
61
 
42
- - Update README to republish faker-cli [\#29](https://github.com/faker-ruby/faker-bot/pull/29) ([vbrazo](https://github.com/vbrazo))
43
62
  - chore: Rename from FakerBot to Faker::CLI [\#28](https://github.com/faker-ruby/faker-bot/pull/28) ([akabiru](https://github.com/akabiru))
44
63
  - Add deprecation notes; thank you contributors! 🎉 [\#25](https://github.com/faker-ruby/faker-bot/pull/25) ([akabiru](https://github.com/akabiru))
45
64
 
@@ -50,10 +69,13 @@
50
69
 
51
70
  - Add Unit tests for `FakerBot::Renderer` [\#11](https://github.com/faker-ruby/faker-bot/issues/11)
52
71
 
72
+ **Fixed bugs:**
73
+
74
+ - Skip Gem::Deprecate Warnings; The CLI handles that [\#19](https://github.com/faker-ruby/faker-bot/pull/19) ([akabiru](https://github.com/akabiru))
75
+
53
76
  **Merged pull requests:**
54
77
 
55
78
  - 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
79
  - Touch Up Tests [\#18](https://github.com/faker-ruby/faker-bot/pull/18) ([akabiru](https://github.com/akabiru))
58
80
  - chore\(workflow\): Add test runner for dev [\#17](https://github.com/faker-ruby/faker-bot/pull/17) ([akabiru](https://github.com/akabiru))
59
81
  - Add CodeClimate [\#16](https://github.com/faker-ruby/faker-bot/pull/16) ([akabiru](https://github.com/akabiru))
@@ -65,9 +87,6 @@
65
87
  **Implemented enhancements:**
66
88
 
67
89
  - Improve Search [\#13](https://github.com/faker-ruby/faker-bot/issues/13)
68
-
69
- **Merged pull requests:**
70
-
71
90
  - Improve search functionality [\#14](https://github.com/faker-ruby/faker-bot/pull/14) ([codealchemy](https://github.com/codealchemy))
72
91
 
73
92
  ## [v0.4.2](https://github.com/faker-ruby/faker-bot/tree/v0.4.2) (2018-10-04)
@@ -81,15 +100,12 @@
81
100
  **Fixed bugs:**
82
101
 
83
102
  - Handle Deprecation Warnings [\#7](https://github.com/faker-ruby/faker-bot/issues/7)
84
-
85
- **Merged pull requests:**
86
-
87
103
  - 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
104
 
89
105
  ## [v0.4.1](https://github.com/faker-ruby/faker-bot/tree/v0.4.1) (2018-09-18)
90
106
  [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.4.0...v0.4.1)
91
107
 
92
- **Merged pull requests:**
108
+ **Fixed bugs:**
93
109
 
94
110
  - Handle Deprecation Warnings [\#10](https://github.com/faker-ruby/faker-bot/pull/10) ([shtakai](https://github.com/shtakai))
95
111
 
@@ -99,15 +115,12 @@
99
115
  **Implemented enhancements:**
100
116
 
101
117
  - Add flag to show sample faker output [\#5](https://github.com/faker-ruby/faker-bot/issues/5)
118
+ - Include Faker sample output [\#6](https://github.com/faker-ruby/faker-bot/pull/6) ([akabiru](https://github.com/akabiru))
102
119
 
103
120
  **Fixed bugs:**
104
121
 
105
122
  - Only show public class methods [\#3](https://github.com/faker-ruby/faker-bot/issues/3)
106
123
 
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
124
  ## [v0.3.0](https://github.com/faker-ruby/faker-bot/tree/v0.3.0) (2018-08-10)
112
125
  [Full Changelog](https://github.com/faker-ruby/faker-bot/compare/v0.2.4...v0.3.0)
113
126
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faker-bot (0.5.0)
4
+ faker-bot (0.5.1)
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 (2.0)
28
+ faker (2.1.0)
29
29
  i18n (>= 0.7)
30
30
  ffi (1.11.1)
31
31
  formatador (0.2.5)
data/README.md CHANGED
@@ -3,8 +3,14 @@
3
3
  [![Build Status](https://travis-ci.org/faker-ruby/faker-bot.svg?branch=master)](https://travis-ci.org/faker-ruby/faker-bot)
4
4
  [![Gem Version](https://badge.fury.io/rb/faker-bot.svg)](https://badge.fury.io/rb/faker-bot)
5
5
  [![Open Source Helpers](https://www.codetriage.com/faker-ruby/faker-bot/badges/users.svg)](https://www.codetriage.com/faker-ruby/faker-bot)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f40541168a0fafbe1808/maintainability)](https://codeclimate.com/github/faker-ruby/faker-bot/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/f40541168a0fafbe1808/test_coverage)](https://codeclimate.com/github/faker-ruby/faker-bot/test_coverage)
6
8
 
7
- > Quickly look up [Faker](https://github.com/stympy/faker) methods without leaving your terminal!
9
+ > Quickly look up [Faker](https://github.com/faker-ruby/faker) methods without leaving your terminal!
10
+
11
+ ![faker-bot-demo](https://user-images.githubusercontent.com/17295175/62558993-c57be080-b882-11e9-972e-7588408d45c3.gif)
12
+
13
+ :book: [Code Documentation](https://www.rubydoc.info/github/faker-ruby/faker-bot)
8
14
 
9
15
  ## Installation
10
16
 
@@ -58,14 +64,6 @@ $ faker search name -v
58
64
  # ....
59
65
  ```
60
66
 
61
- ## New Features! :sunglasses: :dancers:
62
-
63
- - [x] List classes with methods E.g. Faker::FunnyName should list `.name`,`.first_name` e.t.c.
64
- - [x] Expand search to Faker::Base sub classes
65
- - [x] Paginate results :book:
66
-
67
- ![screen shot 2018-08-13 at 23 33 51](https://user-images.githubusercontent.com/17295175/44056603-6343f9f2-9f51-11e8-933d-55367e25be35.jpg)
68
-
69
67
  ## Development
70
68
 
71
69
  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.
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Austin Kabiru"]
10
10
  spec.email = ["makabby@gmail.com"]
11
11
 
12
- spec.summary = %q{A stympy/faker lookup command line tool.}
12
+ spec.summary = %q{A faker-ruby/faker lookup command line tool.}
13
13
  spec.description = %q{Quickly look up Faker methods without leaving your terminal!}
14
14
  spec.homepage = "https://github.com/faker-ruby/faker-bot"
15
15
  spec.license = "MIT"
@@ -6,16 +6,43 @@ require_relative 'renderer'
6
6
 
7
7
  module Faker
8
8
  module Bot
9
+ # @abstract interface for [Command] objects
10
+ #
11
+ # @api private
12
+ #
9
13
  class Command
10
14
  extend Forwardable
11
15
 
12
16
  def_delegators :command, :run
17
+
18
+ # [Command] options
19
+ #
20
+ # @return [Hash<Symbol, String => String, Boolean>]
21
+ #
22
+ # @api private
23
+ #
13
24
  attr_reader :options
14
25
 
26
+ # Initialize the command
27
+ #
28
+ # @param options [Hash<Symbol, String => String, Boolean>]
29
+ # The command options
30
+ #
31
+ # @api public
32
+ #
15
33
  def initialize(options)
16
34
  @options = options
17
35
  end
18
36
 
37
+ # Render the command result into [IO]
38
+ #
39
+ # @param result {Hash} the render tree
40
+ # @param output [IO]
41
+ #
42
+ # @return [IO]
43
+ #
44
+ # @api private
45
+ #
19
46
  def render(result, output)
20
47
  Renderer.call(result, options, output)
21
48
  end
@@ -6,7 +6,17 @@ require_relative '../reflectors/list'
6
6
  module Faker
7
7
  module Bot
8
8
  module Commands
9
+ # Lists all [Faker<Base>] constants
10
+ #
11
+ # @api private
12
+ #
9
13
  class List < Command
14
+ # Execute the `list` command
15
+ #
16
+ # @return [IO]
17
+ #
18
+ # @api private
19
+ #
10
20
  def execute(output: $stdout)
11
21
  result = Reflectors::List.call(options)
12
22
  render(result, output)
@@ -14,12 +24,30 @@ module Faker
14
24
 
15
25
  private
16
26
 
27
+ # Render the search results
28
+ # * Return #not_found when there're no matching results
29
+ #
30
+ # @param result [Hash] the render tree
31
+ # @param output [IO]
32
+ #
33
+ # @return [IO]
34
+ #
35
+ # @api private
36
+ #
17
37
  def render(result, output)
18
38
  return not_found(output) if result.empty?
19
39
 
20
40
  super(result, output)
21
41
  end
22
42
 
43
+ # Render a bespoke "not found" message
44
+ #
45
+ # @param output [IO]
46
+ #
47
+ # @return [IO]
48
+ #
49
+ # @api private
50
+ #
23
51
  def not_found(output)
24
52
  output.puts "\nSorry, that class doesn't exist 😢", "\n",
25
53
  'Try something like `Faker::Beer` or `Beer`.', "\n"
@@ -6,7 +6,17 @@ require_relative '../reflectors/search'
6
6
  module Faker
7
7
  module Bot
8
8
  module Commands
9
+ # Runs a search against [Faker<Base>] methods and returns matching results
10
+ #
11
+ # @api private
12
+ #
9
13
  class Search < Command
14
+ # Execute the `search` command
15
+ #
16
+ # @return [IO]
17
+ #
18
+ # @api private
19
+ #
10
20
  def execute(input, output: $stdout)
11
21
  result = Reflectors::Search.call(input)
12
22
  render(result, output)
@@ -14,12 +24,30 @@ module Faker
14
24
 
15
25
  private
16
26
 
27
+ # Render the search results
28
+ # * Return #not_found when there're no matching results
29
+ #
30
+ # @param result [Hash] the render tree
31
+ # @param output [IO]
32
+ #
33
+ # @return [IO]
34
+ #
35
+ # @api private
36
+ #
17
37
  def render(result, output)
18
38
  return not_found(output) if result.empty?
19
39
 
20
40
  super(result, output)
21
41
  end
22
42
 
43
+ # Render a bespoke "not found" message
44
+ #
45
+ # @param output [IO]
46
+ #
47
+ # @return [IO]
48
+ #
49
+ # @api private
50
+ #
23
51
  def not_found(output)
24
52
  output.puts "\nSorry, we couldn't find a match 😢", "\n"
25
53
  end
@@ -4,18 +4,22 @@ require 'faker'
4
4
 
5
5
  module Faker
6
6
  module Bot
7
- # Abstract `Faker` Reflector - introspects the `Faker` module
7
+ # @abstract `Faker::Base` Reflection object
8
+ # * Introspects the `Faker::Base` class and it's descendants
8
9
  #
9
10
  # @api private
10
- # @abstract
11
11
  #
12
12
  class Reflector
13
13
  Faker::Base.class_eval do
14
14
  # Skip default deprecation warning output; the CLI will display that.
15
15
  Gem::Deprecate.skip = true
16
16
 
17
- # Select `Faker` subclasses
18
- # @return [Array] `Faker::Base` sub classes
17
+ # Select [Faker<Base>] subclasses
18
+ #
19
+ # @return [Array<Class>] `Faker::Base` subclasses
20
+ #
21
+ # @api private
22
+ #
19
23
  def self.descendants
20
24
  @descendants ||= ObjectSpace.each_object(Class).select do |klass|
21
25
  klass < self
@@ -23,26 +27,67 @@ module Faker
23
27
  end
24
28
 
25
29
  # Select public class methods
26
- # @return [Array] public methods
30
+ #
31
+ # @return [Array] singleton public methods
32
+ #
33
+ # @api private
34
+ #
27
35
  def self.my_singleton_methods
28
36
  singleton_methods(false).select { |m| respond_to?(m) }
29
37
  end
30
38
  end
31
39
 
40
+ # @example Faker::Base subclasses with their methods
41
+ # { Faker::Marketing => [:buzzwords], Faker::Artist => [:name] }
42
+ #
43
+ # @return [Hash[Class => [Array<Symbol>]]
44
+ #
45
+ # @api private
46
+ #
32
47
  attr_reader :descendants_with_methods
33
48
 
49
+ # Alternate constructor
50
+ #
51
+ # @see #initialize
52
+ # @see #call
53
+ #
54
+ # @api public
55
+ #
56
+ def self.call(*args)
57
+ new(*args).call
58
+ end
59
+
60
+ # Initialize the reflector
61
+ #
62
+ # @api public
63
+ #
34
64
  def initialize(*)
35
65
  @descendants_with_methods = Hash.new { |h, k| h[k] = [] }
36
66
  end
37
67
 
38
68
  protected
39
69
 
70
+ # Adds a `Faker::Base` descendant methods to the method list
71
+ #
72
+ # @param descendant [Class] The `Faker::Base` subclass
73
+ # @param methods [Array<Symbol>] The `Faker::Base` subclass methods
74
+ #
75
+ # @return [Array<Symbol>]
76
+ #
77
+ # @api private
78
+ #
40
79
  def store(descendant, methods)
41
80
  return if methods.empty?
42
81
 
43
82
  descendants_with_methods[descendant].concat(methods)
44
83
  end
45
84
 
85
+ # Get all `Faker::Base` subclasses
86
+ #
87
+ # @return [Array<Class>]
88
+ #
89
+ # @api public
90
+ #
46
91
  def faker_descendants
47
92
  @faker_descendants ||= Faker::Base.descendants
48
93
  end
@@ -5,17 +5,34 @@ require_relative '../reflector'
5
5
  module Faker
6
6
  module Bot
7
7
  module Reflectors
8
- # List command reflector
8
+ # Reflection object that lists all `Faker::Base` subclasses
9
+ #
9
10
  # @api private
10
11
  #
11
12
  class List < Reflector
13
+ # Output filter
14
+ #
15
+ # @return [String, nil]
16
+ #
17
+ # @api private
18
+ #
12
19
  attr_reader :filter
20
+ # Boolean flag on whether to list methods or not
21
+ #
22
+ # @return [Boolean, nil]
23
+ #
24
+ # @api private
25
+ #
13
26
  attr_reader :show_methods
14
27
 
15
- def self.call(options)
16
- new(options).call
17
- end
18
-
28
+ # Initialize list reflector
29
+ #
30
+ # @param options [Hash{Symbol => Boolean, nil}] Reflector options
31
+ # @option options [Boolean, nil] :show_method
32
+ # Show methods in listing boolean flag
33
+ #
34
+ # @api public
35
+ #
19
36
  def initialize(options = {})
20
37
  @filter = options[:filter]
21
38
  @show_methods = options[:show_methods]
@@ -23,17 +40,39 @@ module Faker
23
40
  super
24
41
  end
25
42
 
43
+ # List `Faker::Base` subclasses
44
+ #
45
+ # @return [Hash<Class => <Array<Symbol>>] when #show_methods is truthy
46
+ #
47
+ # @api private
48
+ #
26
49
  def call
27
- show_methods ? list_descendants_with_methods : list_descendants
50
+ if show_methods
51
+ list_descendants_with_methods
52
+ else
53
+ list_descendants
54
+ end
28
55
  end
29
56
 
30
57
  private
31
58
 
59
+ # List `Faker::Base` subclasses with methods
60
+ #
61
+ # @return [Hash{Class => <Array<Symbol>}]
62
+ #
63
+ # @api private
64
+ #
32
65
  def list_descendants_with_methods
33
66
  list_descendants
34
67
  descendants_with_methods
35
68
  end
36
69
 
70
+ # List `Faker::Base` subclasses
71
+ #
72
+ # @return [Array<Class>]
73
+ #
74
+ # @api private
75
+ #
37
76
  def list_descendants
38
77
  faker_descendants.each do |descendant|
39
78
  if filter_matches_class_name?(descendant.to_s)
@@ -43,9 +82,16 @@ module Faker
43
82
  descendants_with_methods.keys
44
83
  end
45
84
 
85
+ # Match against class name when filter is defined
86
+ #
87
+ # @return [Boolean]
88
+ #
89
+ # @api private
90
+ #
46
91
  def filter_matches_class_name?(class_name)
47
92
  return true unless filter
48
- class_name.match(/#{filter}/)
93
+
94
+ class_name.match(/#{filter}/i)
49
95
  end
50
96
  end
51
97
  end
@@ -5,22 +5,38 @@ require_relative '../reflector'
5
5
  module Faker
6
6
  module Bot
7
7
  module Reflectors
8
- # Find command reflector
8
+ # Reflection object that searches all `Faker::Base` subclass methods
9
+ # * Currently operates at O(n); improvements welcome. :)
10
+ #
9
11
  # @api private
10
12
  #
11
13
  class Search < Reflector
14
+ # Reflector query
15
+ #
16
+ # @return [String, nil]
17
+ #
18
+ # @api private
19
+ #
12
20
  attr_reader :query
13
21
 
14
- def self.call(query)
15
- new(query).call
16
- end
17
-
22
+ # Initialize search reflector
23
+ #
24
+ # @param query [String] The search query
25
+ #
26
+ # @api public
27
+ #
18
28
  def initialize(query)
19
29
  @query = query.downcase
20
30
 
21
31
  super
22
32
  end
23
33
 
34
+ # Search through `Faker::Base` subclasses and return matching results
35
+ #
36
+ # @return [Hash<Class => <Array<Symbol>>] when #show_methods is truthy
37
+ #
38
+ # @api private
39
+ #
24
40
  def call
25
41
  search_descendants_matching_query
26
42
  descendants_with_methods
@@ -28,23 +44,33 @@ module Faker
28
44
 
29
45
  private
30
46
 
47
+ # Search through `Faker::Base` subclasses and store matching results
48
+ #
49
+ # @api private
50
+ #
31
51
  def search_descendants_matching_query
32
52
  faker_descendants.each do |descendant|
33
53
  methods = descendant.my_singleton_methods
34
- if query_matches_class_name?(descendant.to_s)
54
+
55
+ if query_matches?(descendant)
35
56
  store(descendant, methods)
36
57
  else
37
- store(descendant, methods.select { |method| query_matches_method?(method.to_s) })
58
+ store(
59
+ descendant,
60
+ methods.select { |method| query_matches?(method) }
61
+ )
38
62
  end
39
63
  end
40
64
  end
41
65
 
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}/)
66
+ # Match a subject against the query string
67
+ #
68
+ # @return [Boolean]
69
+ #
70
+ # @api private
71
+ #
72
+ def query_matches?(subject)
73
+ subject.to_s.match(/#{query}/i)
48
74
  end
49
75
  end
50
76
  end
@@ -7,21 +7,45 @@ require 'tty/tree'
7
7
 
8
8
  module Faker
9
9
  module Bot
10
+ # A class responsible for printing output to an [IO] interface
11
+ #
12
+ # @api private
13
+ #
10
14
  class Renderer
15
+ DEPRECATION_WARNING = ' ( WILL BE DEPRECATED )'
16
+ EMPTY = ''
17
+ NOT_AVAILABLE = 'N/A'
18
+
11
19
  attr_reader :crayon, :hash, :options, :output, :pager
12
20
 
13
21
  def self.call(*args)
14
22
  new(*args).call
15
23
  end
16
24
 
25
+ # Initialize a Render
26
+ #
27
+ # @param hash [Hash<Class => <Array<Symbol>>]
28
+ # @param options [Hash]
29
+ # @param output [IO]
30
+ #
31
+ # @api public
32
+ #
17
33
  def initialize(hash, options, output)
18
34
  @hash = hash
19
35
  @options = options
20
36
  @output = output
37
+
21
38
  @crayon = Pastel.new(enabled: output.tty?)
22
39
  @pager = TTY::Pager.new(command: 'less -R')
23
40
  end
24
41
 
42
+ # Print paginated output if the terminal interface supports pagination.
43
+ # Otherwise, just print the full output
44
+ #
45
+ # @return [IO]
46
+ #
47
+ # @api private
48
+ #
25
49
  def call
26
50
  if paginable?
27
51
  pager.page(render)
@@ -30,24 +54,54 @@ module Faker
30
54
  end
31
55
  end
32
56
 
57
+ # Render the structured data tree
58
+ #
59
+ # @return [String]
60
+ #
61
+ # @api private
62
+ #
33
63
  def render
34
64
  tree.render
35
65
  end
36
66
 
67
+ # Warm up the structured data tree render object
68
+ #
69
+ # @return [TTY<Tree>]
70
+ #
71
+ # @api private
72
+ #
37
73
  def tree
38
74
  @tree ||= TTY::Tree.new(build_tree)
39
75
  end
40
76
 
77
+ # Check whether the terminal interface supports pagination
78
+ #
79
+ # @return [Boolean]
80
+ #
81
+ # @api private
82
+ #
41
83
  def paginable?
42
84
  gt_screen_height? && output.tty?
43
85
  end
44
86
 
87
+ # Check whether the tree size is greater than current screen height
88
+ #
89
+ # @return [Boolean]
90
+ #
91
+ # @api private
92
+ #
45
93
  def gt_screen_height?
46
94
  tree.nodes.size > TTY::Screen.height
47
95
  end
48
96
 
49
97
  private
50
98
 
99
+ # Build the structured data tree sorted alphabetically
100
+ #
101
+ # @return [Hash{Class => <Array<Symbol>}]
102
+ #
103
+ # @api private
104
+ #
51
105
  def build_tree
52
106
  results = hash.reduce({}) do |h, (const, methods)|
53
107
  h.merge! node(const, methods&.sort)
@@ -56,37 +110,84 @@ module Faker
56
110
  results.sort_by(&:to_s).to_h
57
111
  end
58
112
 
113
+ # Tree node builder with color
114
+ #
115
+ # @return [Hash{Class => <Array<Symbol>}]
116
+ #
117
+ # @api private
118
+ #
59
119
  def node(const, methods)
60
120
  {
61
121
  crayon.green(const.to_s) => leaf(const, methods)
62
122
  }
63
123
  end
64
124
 
125
+ # Tree leaf builder with color
126
+ #
127
+ # @return [Array<Symbol>]
128
+ #
129
+ # @api private
130
+ #
65
131
  def leaf(const, methods)
66
132
  (methods || []).map { |m| crayon.cyan(*leaf_args(m, const)) }
67
133
  end
68
134
 
69
135
  def leaf_args(method, const)
70
- [method.to_s].tap { |arr| verbose_output(method, const, arr) if verbose? }
136
+ [method.to_s].tap do |arr|
137
+ verbose_output(method, const, arr) if verbose?
138
+ end
71
139
  end
72
140
 
141
+ # Boolean verbose option flag
142
+ #
143
+ # @return [Boolean]
144
+ #
145
+ # @api private
146
+ #
73
147
  def verbose?
74
148
  options[:verbose]
75
149
  end
76
150
 
151
+ # Generate verbose output via sample fake data
152
+ #
153
+ # @return [Array<String>]
154
+ #
155
+ # @api private
156
+ #
77
157
  def verbose_output(method, const, arr)
78
158
  fake, message = faker_method(method, const)
79
- arr << crayon.dim.white("=> #{fake}") << crayon.dim.magenta.bold(message.to_s)
159
+
160
+ arr.push(crayon.dim.white("=> #{fake}"))
161
+ .push(crayon.dim.magenta.bold(message.to_s))
80
162
  end
81
163
 
164
+ # Send message to Faker object; receive sample fake data
165
+ #
166
+ # @return [Array<String>]
167
+ #
168
+ # @api private
169
+ #
82
170
  def faker_method(method, const)
83
- [const.public_send(method), ensure_method_is_supported(method, const)]
171
+ [
172
+ const.public_send(method),
173
+ ensure_method_is_supported(method, const)
174
+ ]
84
175
  rescue ArgumentError => _e
85
- ['N/A', '']
176
+ [NOT_AVAILABLE, EMPTY]
86
177
  end
87
178
 
179
+ # Mark deprecated methods
180
+ #
181
+ # @return [String]
182
+ #
183
+ # @api private
184
+ #
88
185
  def ensure_method_is_supported(method, const)
89
- const.respond_to?(:"_deprecated_#{method}") ? ' ( WILL BE DEPRECATED )' : ''
186
+ if const.respond_to?(:"_deprecated_#{method}")
187
+ DEPRECATION_WARNING
188
+ else
189
+ EMPTY
190
+ end
90
191
  end
91
192
  end
92
193
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faker
4
4
  module Bot
5
- VERSION = '0.5.0'
5
+ VERSION = '0.5.1'
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.5.0
4
+ version: 0.5.1
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-31 00:00:00.000000000 Z
11
+ date: 2019-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker
@@ -200,6 +200,7 @@ executables:
200
200
  extensions: []
201
201
  extra_rdoc_files: []
202
202
  files:
203
+ - ".codeclimate.yml"
203
204
  - ".github/main.workflow"
204
205
  - ".gitignore"
205
206
  - ".rspec"
@@ -251,5 +252,5 @@ rubyforge_project:
251
252
  rubygems_version: 2.7.6
252
253
  signing_key:
253
254
  specification_version: 4
254
- summary: A stympy/faker lookup command line tool.
255
+ summary: A faker-ruby/faker lookup command line tool.
255
256
  test_files: []