fakerbot 0.1.2 → 0.2.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
  SHA1:
3
- metadata.gz: f9e62943ce7b36a4ab383901b4b281daf350a1e4
4
- data.tar.gz: d1370e82322c2b570e6741f69251323fbde712aa
3
+ metadata.gz: d6f9c6012e690d78b9fe3312c3df35ab4e9f0fb0
4
+ data.tar.gz: ba34f6335dbfc51d8cec5f4d81e8886053da87e5
5
5
  SHA512:
6
- metadata.gz: bf248135d9f6479bbba38b6cebdc43db3e94bdbd5af936f6a9da78edf8e3a77ee4647330e21cd89988c7bf2dcaed97520833605eb47f7107baef9bf673104f7e
7
- data.tar.gz: 6709287731922e6cda4b897f65aec24eac92f83684912417d633cde4400409cb5bca630aa4c8bb6df3f4f97f86c905f66176429f8fadccee38ef841f186ea9ba
6
+ metadata.gz: 22b90cab9064cb1e24f6f71bef7e6df71af6e70a81615a51a894dd70820e90897dd1c71f3f93175c0ccfeb1385415823ce0b5076007851aded1feadba9eaa24d
7
+ data.tar.gz: 97d80d7590d2758720536390d31cdd909f0c7e2f16bf8ecb2416799ece3e6db83c8c5fa3bb947c4dd4aec41d8f6a93a2dcfdb91b0ee56cc80527736f9296e63c
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakerbot (0.1.1)
4
+ fakerbot (0.1.2)
5
5
  faker
6
6
  pastel (~> 0.7.2)
7
7
  thor (~> 0.20.0)
8
+ tty-tree
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
@@ -22,11 +23,11 @@ GEM
22
23
  domain_name (0.5.20180417)
23
24
  unf (>= 0.0.5, < 1.0.0)
24
25
  equatable (0.5.0)
25
- faker (1.8.7)
26
+ faker (1.9.1)
26
27
  i18n (>= 0.7)
27
28
  http-cookie (1.0.3)
28
29
  domain_name (~> 0.5)
29
- i18n (1.0.1)
30
+ i18n (1.1.0)
30
31
  concurrent-ruby (~> 1.0)
31
32
  json (2.1.0)
32
33
  method_source (0.9.0)
@@ -68,7 +69,8 @@ GEM
68
69
  tins (~> 1.0)
69
70
  thor (0.20.0)
70
71
  tins (1.16.3)
71
- tty-color (0.4.2)
72
+ tty-color (0.4.3)
73
+ tty-tree (0.1.0)
72
74
  unf (0.1.4)
73
75
  unf_ext
74
76
  unf_ext (0.0.7.5)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # FakerBot
2
2
 
3
- [![codebeat badge](https://codebeat.co/badges/ef4839f2-3946-4435-8c0e-7025de5fac22)](https://codebeat.co/projects/github-com-akabiru-faker_bot-master) [![Inline docs](http://inch-ci.org/github/akabiru/faker_bot.svg?branch=master)](http://inch-ci.org/github/akabiru/faker_bot) [![Build Status](https://travis-ci.com/akabiru/faker_bot.svg?branch=master)](https://travis-ci.com/akabiru/faker_bot) [![Coverage Status](https://coveralls.io/repos/github/akabiru/faker_bot/badge.svg?branch=master)](https://coveralls.io/github/akabiru/faker_bot?branch=master) [![Gem Version](https://badge.fury.io/rb/fakerbot.svg)](https://badge.fury.io/rb/fakerbot)
3
+ [![codebeat badge](https://codebeat.co/badges/ef4839f2-3946-4435-8c0e-7025de5fac22)](https://codebeat.co/projects/github-com-akabiru-fakerbot-master) [![Inline docs](http://inch-ci.org/github/akabiru/fakerbot.svg?branch=master)](http://inch-ci.org/github/akabiru/fakerbot) [![Build Status](https://travis-ci.com/akabiru/fakerbot.svg?branch=master)](https://travis-ci.com/akabiru/fakerbot) [![Coverage Status](https://coveralls.io/repos/github/akabiru/fakerbot/badge.svg?branch=master)](https://coveralls.io/github/akabiru/fakerbot?branch=master) [![Gem Version](https://badge.fury.io/rb/fakerbot.svg)](https://badge.fury.io/rb/fakerbot)
4
4
 
5
5
  > Quickly look up [Faker](https://github.com/stympy/faker) methods without leaving your terminal!
6
6
 
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "faker"
23
23
  spec.add_dependency "pastel", "~> 0.7.2"
24
24
  spec.add_dependency "thor", "~> 0.20.0"
25
+ spec.add_dependency "tty-tree"
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.16"
27
28
  spec.add_development_dependency "coveralls"
@@ -10,18 +10,51 @@ module FakerBot
10
10
  klass < self
11
11
  end
12
12
  end
13
+
14
+ def self.my_singleton_methods
15
+ if superclass
16
+ (singleton_methods - superclass.singleton_methods)
17
+ else
18
+ singleton_methods
19
+ end
20
+ end
21
+ end
22
+
23
+ attr_reader :matching_descendants, :query
24
+
25
+ def initialize(query)
26
+ @matching_descendants = Hash.new { |h, k| h[k] = [] }
27
+ @query = query
13
28
  end
14
29
 
15
30
  class << self
16
31
  def find(query)
17
- faker_descendants.select { |faker| faker.match?(/#{query}/i) }
32
+ new(query).find
18
33
  end
34
+ end
19
35
 
20
- private
36
+ def find
37
+ search_descendants_matching_query
38
+ matching_descendants
39
+ end
40
+
41
+ private
21
42
 
22
- def faker_descendants
23
- @faker_descendants ||= Faker::Base.descendants.map(&:to_s)
43
+ def search_descendants_matching_query
44
+ faker_descendants.each do |faker|
45
+ methods = faker.my_singleton_methods
46
+ matching = methods.select { |m| m.match?(/#{query}/i) }
47
+ save_matching(faker, matching)
24
48
  end
25
49
  end
50
+
51
+ def save_matching(descendant, matching)
52
+ return if matching.empty?
53
+ matching_descendants[descendant].concat(matching)
54
+ end
55
+
56
+ def faker_descendants
57
+ @faker_descendants ||= Faker::Base.descendants
58
+ end
26
59
  end
27
60
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pastel'
4
+ require 'tty/tree'
4
5
  require 'fakerbot/bot'
5
6
 
6
7
  module FakerBot
@@ -12,7 +13,17 @@ module FakerBot
12
13
 
13
14
  def execute(input)
14
15
  result = FakerBot::Bot.find(input)
15
- puts(result.map { |r| Pastel.new.green(r) })
16
+ puts tree(result).render
17
+ end
18
+
19
+ def tree(input)
20
+ TTY::Tree.new do
21
+ input.each do |faker, methods|
22
+ node Pastel.new.green(faker.to_s) do
23
+ methods.each { |m| leaf Pastel.new.cyan(m.to_s) }
24
+ end
25
+ end
26
+ end
16
27
  end
17
28
  end
18
29
  end
@@ -1,3 +1,3 @@
1
1
  module FakerBot
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakerbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.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: 2018-07-24 00:00:00.000000000 Z
11
+ date: 2018-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.20.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-tree
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'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement