diff --git a/Gemfile.lock b/Gemfile.lock index d7f2c54..b1fc68b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - fakerbot (0.3.0) + fakerbot (0.4.0) faker pastel (~> 0.7.2) thor (~> 0.20.0) @@ -67,8 +67,8 @@ GEM json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - strings (0.1.1) - unicode-display_width (~> 1.3.0) + strings (0.1.2) + unicode-display_width (~> 1.4.0) unicode_utils (~> 1.4.0) term-ansicolor (1.6.0) tins (~> 1.0) @@ -85,7 +85,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.5) - unicode-display_width (1.3.3) + unicode-display_width (1.4.0) unicode_utils (1.4.0) PLATFORMS diff --git a/lib/fakerbot/cli.rb b/lib/fakerbot/cli.rb index 2efebdd..398a62c 100644 --- a/lib/fakerbot/cli.rb +++ b/lib/fakerbot/cli.rb @@ -20,8 +20,10 @@ def version desc 'list', 'List all Faker constants' method_option :help, aliases: '-h', type: :boolean, desc: 'Display usage information' + method_option :show_methods, aliases: '-m', type: :boolean, default: true, + desc: 'Display Faker constants with methods' method_option :verbose, aliases: '-v', type: :boolean, - desc: 'Display Faker constants with methods' + desc: 'Include sample Faker output' def list(*) if options[:help] invoke :help, ['list'] @@ -33,8 +35,10 @@ def list(*) desc 'search [Faker]', 'Search Faker method(s)' method_option :help, aliases: '-h', type: :boolean, desc: 'Display usage information' + method_option :show_methods, aliases: '-m', type: :boolean, default: true, + desc: 'Display Faker constants with methods' method_option :verbose, aliases: '-v', type: :boolean, - desc: 'Display Faker constants methods with examples' + desc: 'Include sample Faker output' def search(query) if options[:help] invoke :help, ['search'] diff --git a/lib/fakerbot/commands/list.rb b/lib/fakerbot/commands/list.rb index 2bfddc6..fafc8b1 100644 --- a/lib/fakerbot/commands/list.rb +++ b/lib/fakerbot/commands/list.rb @@ -10,7 +10,8 @@ def initialize(options) end def execute(output: $stdout) - render FakerBot::Reflector.list(verbose: @options[:verbose]), output + result = FakerBot::Reflector.list(show_methods: options[:show_methods]) + render result, output end end end diff --git a/lib/fakerbot/reflector.rb b/lib/fakerbot/reflector.rb index b6f47ad..82e214f 100644 --- a/lib/fakerbot/reflector.rb +++ b/lib/fakerbot/reflector.rb @@ -34,8 +34,8 @@ def find(query) new(query).find end - def list(verbose: false) - new.list(verbose) + def list(show_methods: false) + new.list(show_methods) end end @@ -44,8 +44,8 @@ def find descendants_with_methods end - def list(verbose) - verbose ? all_descendants_with_methods : faker_descendants + def list(show_methods) + show_methods ? all_descendants_with_methods : faker_descendants end private diff --git a/lib/fakerbot/renderer.rb b/lib/fakerbot/renderer.rb index 99299ac..2241f0a 100644 --- a/lib/fakerbot/renderer.rb +++ b/lib/fakerbot/renderer.rb @@ -49,17 +49,20 @@ def node(const, methods) def leaf(const, methods) (methods || []).map do |m| - args = [m.to_s].tap do |a| - if show_examples? - fake = begin - const.public_send(m) - rescue ArgumentError - 'N/A' - end - a << pastel.dim.white("=> #{fake.to_s}") + crayon.cyan(*leaf_args(m, const)) + end + end + + def leaf_args(method, const) + [method.to_s].tap do |arr| + if verbose? + fake = begin + const.public_send(method) + rescue ArgumentError + 'N/A' end + arr << crayon.dim.white("=> #{fake.to_s}") end - crayon.cyan(*args) end end @@ -67,8 +70,8 @@ def gt_screen_height?(data_tree) data_tree.nodes.size > screen.height end - def show_examples? - options[:show_examples] + def verbose? + options[:verbose] end end end diff --git a/lib/fakerbot/version.rb b/lib/fakerbot/version.rb index 0f4eb0c..0e2091d 100644 --- a/lib/fakerbot/version.rb +++ b/lib/fakerbot/version.rb @@ -1,3 +1,3 @@ module FakerBot - VERSION = '0.3.0'.freeze + VERSION = '0.4.0'.freeze end diff --git a/spec/integration/list_spec.rb b/spec/integration/list_spec.rb index f38b686..ddf7d98 100644 --- a/spec/integration/list_spec.rb +++ b/spec/integration/list_spec.rb @@ -8,13 +8,15 @@ fakerbot list Options: - -h, [--help], [--no-help] # Display usage information - -v, [--verbose], [--no-verbose] # Display Faker constants with methods + -h, [--help], [--no-help] # Display usage information + -m, [--show-methods], [--no-show-methods] # Display Faker constants with methods + # Default: true + -v, [--verbose], [--no-verbose] # Include sample Faker output List all Faker constants OUT - expect(output).to eq(expected_output) + expect(output).to match(expected_output) end it 'executes `fakerbot list` command successfully' do diff --git a/spec/integration/search_spec.rb b/spec/integration/search_spec.rb index c9c8aac..a7b7c9e 100644 --- a/spec/integration/search_spec.rb +++ b/spec/integration/search_spec.rb @@ -8,13 +8,14 @@ fakerbot search [Faker] Options: - -h, [--help], [--no-help] # Display usage information - -v, [--verbose], [--no-verbose] # Display Faker constants methods with examples + -h, [--help], [--no-help] # Display usage information + -m, [--show-methods], [--no-show-methods] # Display Faker constants with methods + # Default: true + -v, [--verbose], [--no-verbose] # Include sample Faker output Search Faker method(s) OUT - - expect(output).to eq(expected_output) + expect(output).to match(expected_output) end context 'when search query exists' do diff --git a/spec/unit/list_spec.rb b/spec/unit/list_spec.rb index 363bfd6..40113b2 100644 --- a/spec/unit/list_spec.rb +++ b/spec/unit/list_spec.rb @@ -21,11 +21,8 @@ it 'executes successfully' do constant = output.string.lines[0] - method = output.string.lines[1] expect(constant).to match(/Faker::/) - expect(method).not_to match(/Faker::/) - expect(method).to match(/└──/) end end end