factory_bot-awesome_linter 0.0.1 → 1.0.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: 617261095c26b3a682b99159a3cde1ec380c854be48bef7be0828db2e50c02a0
4
- data.tar.gz: 9d2ab786572209fb46735949648e2efb78c1dcfd55ee4a5e6ea1cac2bd51df4f
3
+ metadata.gz: 8740b68a3f7d66f034238f1c3873a02a665571de253901041a2855938d9d11e8
4
+ data.tar.gz: ad15e4c9237b2e764323ba7b30b9c1346159c36409889ebeffe15ddbdea9e95f
5
5
  SHA512:
6
- metadata.gz: b5f9217d10a5ece6f8375f750866de7d77d9ea58be815a3296468ed095d518d471c4e5951138c1ab0e54e8784effcb559b35ba2b5de04bbeb3b6b0b6c80b0eff
7
- data.tar.gz: dfdf9392b11e132c1fad5c3ce4f07182e1c1f599623ef72ed01132305d88f5afeb3d577f7d605fa44c8f30021ee9bf2c2185765a38e006e9578515fd8c33bb05
6
+ metadata.gz: 22bd532a03b0b38b66d8f5d4de4acc509f19b76c18665efcdfaf37e311c2df5c43f2d273299757761015c24e94deec70959813ff960d6e8bc4cc6da0c569e2eb
7
+ data.tar.gz: 1705cf66aa84b8a8970080de648b129a4a3b8d4cb64efefe39b47cd2fdcc61953dde8e45566de27a57fdd71f93af39d6160b498f6c0854f5ea5a545920e51e7c
@@ -9,17 +9,11 @@ module FactoryBot
9
9
  new(*args, **kwargs).lint!
10
10
  end
11
11
 
12
- def initialize(*args, strategy: :create, traits: false, verbose: false)
13
- if args.any?
14
- @factories_to_lint = args[0]
15
- else
16
- FactoryBot.reload
17
- @factories_to_lint = FactoryBot.factories
18
- end
12
+ def initialize(*args, strategy: :create, traits: false)
13
+ @factories_to_lint = load_factories(*args)
19
14
 
20
15
  @factory_strategy = strategy
21
16
  @traits = traits
22
- @verbose = verbose
23
17
  @progress_bar = ProgressBar.create(format: "\e[0;32m %c/%C |%w>%i| %e \e[0m")
24
18
  @invalid_factories = []
25
19
  end
@@ -47,12 +41,35 @@ module FactoryBot
47
41
  invalid_factories.empty?
48
42
  end
49
43
 
44
+ def load_factories(*args)
45
+ p args
46
+
47
+ FactoryBot.reload
48
+ return FactoryBot.factories if args.empty?
49
+
50
+ args.flat_map do |arg|
51
+ case arg
52
+ when Symbol, String
53
+ FactoryBot.factories.find(arg)
54
+ when Regexp
55
+ FactoryBot.factories.select { |factory| factory.name.match?(arg) }
56
+ when FactoryBot::Factory
57
+ arg
58
+ else
59
+ raise TypeError, "unexpected argument: #{arg}"
60
+ end
61
+ end
62
+ end
63
+
50
64
  def calculate_total
51
65
  factories_to_lint.reduce(0) do |count, factory|
52
- # Compile factory to count enum traits
53
- factory.compile
54
-
55
- count + 1 + factory.definition.defined_traits.size
66
+ if @traits
67
+ # Compile factory to count enum traits
68
+ factory.compile
69
+ count + 1 + factory.definition.defined_traits.size
70
+ else
71
+ count + 1
72
+ end
56
73
  end
57
74
  end
58
75
 
@@ -1,5 +1,5 @@
1
1
  module FactoryBot
2
2
  class AwesomeLinter
3
- VERSION = '0.0.1'.freeze
3
+ VERSION = '1.0.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_bot-awesome_linter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Savater Sebastien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-08 00:00:00.000000000 Z
11
+ date: 2021-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot