fakerbot 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fakerbot/bot.rb +23 -8
- data/lib/fakerbot/cli.rb +15 -1
- data/lib/fakerbot/command.rb +43 -0
- data/lib/fakerbot/commands/list.rb +17 -0
- data/lib/fakerbot/commands/search.rb +6 -27
- data/lib/fakerbot/templates/list/.gitkeep +1 -0
- data/lib/fakerbot/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 837cc2d92e1c31ad78fd7adc057fb11178d89bea
|
4
|
+
data.tar.gz: 02e139d11db43948282be5cf4694cdc1cdda9db2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82e8003271e1e494021551910a83b8c252a41f0aae71fb77b01c067ac2efafda4b456a8d56714544dde8d7f888d0161ee2966ce14efb75534f043ce8faf8d465
|
7
|
+
data.tar.gz: bca6bd5310bf359267b52ad0ea2ac454dfc0432e59bd023d13e54e2857e645e939eb8d52e900a4758b93e04b623ac9b6b55605083415beff49c82c0770426f9d
|
data/Gemfile.lock
CHANGED
data/lib/fakerbot/bot.rb
CHANGED
@@ -20,10 +20,10 @@ module FakerBot
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
attr_reader :
|
23
|
+
attr_reader :descendants_with_methods, :query
|
24
24
|
|
25
|
-
def initialize(query)
|
26
|
-
@
|
25
|
+
def initialize(query = nil)
|
26
|
+
@descendants_with_methods = Hash.new { |h, k| h[k] = [] }
|
27
27
|
@query = query
|
28
28
|
end
|
29
29
|
|
@@ -31,26 +31,41 @@ module FakerBot
|
|
31
31
|
def find(query)
|
32
32
|
new(query).find
|
33
33
|
end
|
34
|
+
|
35
|
+
def list(verbose: false)
|
36
|
+
new.list(verbose)
|
37
|
+
end
|
34
38
|
end
|
35
39
|
|
36
40
|
def find
|
37
41
|
search_descendants_matching_query
|
38
|
-
|
42
|
+
descendants_with_methods
|
43
|
+
end
|
44
|
+
|
45
|
+
def list(verbose)
|
46
|
+
verbose ? all_descendants_with_methods : faker_descendants
|
39
47
|
end
|
40
48
|
|
41
49
|
private
|
42
50
|
|
51
|
+
def all_descendants_with_methods
|
52
|
+
faker_descendants.each do |faker|
|
53
|
+
store(faker, faker.my_singleton_methods)
|
54
|
+
end
|
55
|
+
descendants_with_methods
|
56
|
+
end
|
57
|
+
|
43
58
|
def search_descendants_matching_query
|
44
59
|
faker_descendants.each do |faker|
|
45
60
|
methods = faker.my_singleton_methods
|
46
61
|
matching = methods.select { |m| m.match?(/#{query}/i) }
|
47
|
-
|
62
|
+
store(faker, matching)
|
48
63
|
end
|
49
64
|
end
|
50
65
|
|
51
|
-
def
|
52
|
-
return if
|
53
|
-
|
66
|
+
def store(descendant, methods)
|
67
|
+
return if methods.empty?
|
68
|
+
descendants_with_methods[descendant].concat(methods)
|
54
69
|
end
|
55
70
|
|
56
71
|
def faker_descendants
|
data/lib/fakerbot/cli.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'thor'
|
4
4
|
require 'fakerbot/cli'
|
5
5
|
require 'fakerbot/version'
|
6
|
+
require 'fakerbot/commands/list'
|
6
7
|
require 'fakerbot/commands/search'
|
7
8
|
|
8
9
|
module FakerBot
|
@@ -16,11 +17,24 @@ module FakerBot
|
|
16
17
|
end
|
17
18
|
map %w[--version -v] => :version
|
18
19
|
|
20
|
+
desc 'list', 'List all Faker constants'
|
21
|
+
method_option :help, aliases: '-h', type: :boolean,
|
22
|
+
desc: 'Display usage information'
|
23
|
+
method_option :verbose, aliases: '-v', type: :boolean,
|
24
|
+
desc: 'Display Faker constants with methods'
|
25
|
+
def list(*)
|
26
|
+
if options[:help]
|
27
|
+
invoke :help, ['list']
|
28
|
+
else
|
29
|
+
FakerBot::Commands::List.new(options).execute
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
19
33
|
desc 'search [Faker]', 'Search Faker method(s)'
|
20
34
|
method_option :help, aliases: '-h', type: :boolean,
|
21
35
|
desc: 'Display usage information'
|
22
36
|
method_option :verbose, aliases: '-v', type: :boolean,
|
23
|
-
desc: 'Display Faker
|
37
|
+
desc: 'Display Faker constants methods with examples'
|
24
38
|
def search(query)
|
25
39
|
if options[:help]
|
26
40
|
invoke :help, ['search']
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
require 'pastel'
|
5
|
+
require 'tty/pager'
|
6
|
+
require 'tty/tree'
|
7
|
+
|
8
|
+
module FakerBot
|
9
|
+
class Command
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
def_delegators :command, :run
|
13
|
+
|
14
|
+
def pager
|
15
|
+
TTY::Pager.new(command: 'less -R')
|
16
|
+
end
|
17
|
+
|
18
|
+
def screen
|
19
|
+
TTY::Screen
|
20
|
+
end
|
21
|
+
|
22
|
+
def tree(input)
|
23
|
+
TTY::Tree.new do
|
24
|
+
input.each do |faker, methods|
|
25
|
+
node Pastel.new.green(faker.to_s) do
|
26
|
+
methods&.each { |m| leaf Pastel.new.cyan(m.to_s) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def render(result, output = $stdout)
|
33
|
+
result_tree = tree(result)
|
34
|
+
view = result_tree.render
|
35
|
+
if screen.height < result_tree.nodes.size
|
36
|
+
# paginate when attached to terminal
|
37
|
+
output.tty? ? pager.page(view) : output.puts(view)
|
38
|
+
else
|
39
|
+
output.puts view
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
|
5
|
+
module FakerBot
|
6
|
+
module Commands
|
7
|
+
class List < FakerBot::Command
|
8
|
+
def initialize(options)
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(output: $stdout)
|
13
|
+
render FakerBot::Bot.list(verbose: @options[:verbose]), output
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,45 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'pastel'
|
4
|
-
require 'tty/pager'
|
5
|
-
require 'tty/tree'
|
6
3
|
require 'fakerbot/bot'
|
4
|
+
require_relative '../command'
|
7
5
|
|
8
6
|
module FakerBot
|
9
7
|
module Commands
|
10
|
-
class Search
|
8
|
+
class Search < FakerBot::Command
|
11
9
|
def initialize(options)
|
12
10
|
@options = options
|
13
|
-
@pager = TTY::Pager.new(command: 'less -R')
|
14
|
-
@screen = TTY::Screen
|
15
11
|
end
|
16
12
|
|
17
|
-
def execute(input)
|
18
|
-
render FakerBot::Bot.find(input)
|
13
|
+
def execute(input, output: $stdout)
|
14
|
+
render FakerBot::Bot.find(input), output
|
19
15
|
end
|
20
16
|
|
21
17
|
private
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
def render(result)
|
19
|
+
def render(result, output)
|
26
20
|
return not_found if result.empty?
|
27
|
-
|
28
|
-
if screen.height < output.nodes.size
|
29
|
-
pager.page output.render
|
30
|
-
else
|
31
|
-
puts output.render
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def tree(input)
|
36
|
-
TTY::Tree.new do
|
37
|
-
input.each do |faker, methods|
|
38
|
-
node Pastel.new.green(faker.to_s) do
|
39
|
-
methods.each { |m| leaf Pastel.new.cyan(m.to_s) }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
21
|
+
super(result, output)
|
43
22
|
end
|
44
23
|
|
45
24
|
def not_found
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
data/lib/fakerbot/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakerbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Austin Kabiru
|
@@ -204,7 +204,10 @@ files:
|
|
204
204
|
- lib/fakerbot.rb
|
205
205
|
- lib/fakerbot/bot.rb
|
206
206
|
- lib/fakerbot/cli.rb
|
207
|
+
- lib/fakerbot/command.rb
|
208
|
+
- lib/fakerbot/commands/list.rb
|
207
209
|
- lib/fakerbot/commands/search.rb
|
210
|
+
- lib/fakerbot/templates/list/.gitkeep
|
208
211
|
- lib/fakerbot/version.rb
|
209
212
|
homepage: https://github.com/akabiru/fakerbot
|
210
213
|
licenses:
|