fixturex 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +37 -0
- data/.gitignore +10 -0
- data/.travis.yml +6 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +204 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +12 -0
- data/bin/console +17 -0
- data/bin/fixturex +14 -0
- data/bin/fixturex.rb +25 -0
- data/bin/setup +8 -0
- data/fixturex.gemspec +33 -0
- data/lib/fixturex/fixture_location.rb +25 -0
- data/lib/fixturex/tree_builder.rb +101 -0
- data/lib/fixturex/tree_entry.rb +10 -0
- data/lib/fixturex/version.rb +5 -0
- data/lib/fixturex/vimgrep_tree_formatter.rb +37 -0
- data/lib/fixturex.rb +4 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4ea06be8bc96efed28b5178afcb2067df1f62e33ffcbab770b4e9f8981d7c4c7
|
4
|
+
data.tar.gz: bdf4a376118d64737bd158430543dfa8cd4f072f5b47f22aee79f9d5faf316c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a84ac2f32931c6302e3fe0f7d51e7857faf55ed82c84d333b6c9f5989737367859574e1c53a70a296bda588073e8233ad9f8b4e29b8a726b372957d75d7bdcb7
|
7
|
+
data.tar.gz: df1e9d6e317c08ffb17d1d657220486d499b78a3ac3630290ff9834787b4b1c598e58f29f9fdf8e661bb0a7a5aa23b2abc7cc9b41fadbdfbc6be4967de4d3ae0
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
paths-ignore:
|
14
|
+
- 'README.md'
|
15
|
+
pull_request:
|
16
|
+
branches: [ main ]
|
17
|
+
|
18
|
+
jobs:
|
19
|
+
test:
|
20
|
+
|
21
|
+
runs-on: ubuntu-latest
|
22
|
+
strategy:
|
23
|
+
matrix:
|
24
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
25
|
+
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- name: Set up Ruby
|
29
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
30
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
31
|
+
# uses: ruby/setup-ruby@v1
|
32
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
33
|
+
with:
|
34
|
+
ruby-version: ${{ matrix.ruby-version }}
|
35
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
36
|
+
- name: Run tests
|
37
|
+
run: COVERAGE=1 bundle exec rspec
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in fixturex.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'awesome_print'
|
9
|
+
gem 'rake'
|
10
|
+
gem 'rspec'
|
11
|
+
gem 'rspec-rails'
|
12
|
+
gem 'rubocop'
|
13
|
+
gem 'simplecov'
|
14
|
+
gem 'sqlite3'
|
15
|
+
gem 'byebug'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fixturex (0.1.0)
|
5
|
+
rails (>= 6.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (6.1.4.1)
|
11
|
+
actionpack (= 6.1.4.1)
|
12
|
+
activesupport (= 6.1.4.1)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailbox (6.1.4.1)
|
16
|
+
actionpack (= 6.1.4.1)
|
17
|
+
activejob (= 6.1.4.1)
|
18
|
+
activerecord (= 6.1.4.1)
|
19
|
+
activestorage (= 6.1.4.1)
|
20
|
+
activesupport (= 6.1.4.1)
|
21
|
+
mail (>= 2.7.1)
|
22
|
+
actionmailer (6.1.4.1)
|
23
|
+
actionpack (= 6.1.4.1)
|
24
|
+
actionview (= 6.1.4.1)
|
25
|
+
activejob (= 6.1.4.1)
|
26
|
+
activesupport (= 6.1.4.1)
|
27
|
+
mail (~> 2.5, >= 2.5.4)
|
28
|
+
rails-dom-testing (~> 2.0)
|
29
|
+
actionpack (6.1.4.1)
|
30
|
+
actionview (= 6.1.4.1)
|
31
|
+
activesupport (= 6.1.4.1)
|
32
|
+
rack (~> 2.0, >= 2.0.9)
|
33
|
+
rack-test (>= 0.6.3)
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
+
actiontext (6.1.4.1)
|
37
|
+
actionpack (= 6.1.4.1)
|
38
|
+
activerecord (= 6.1.4.1)
|
39
|
+
activestorage (= 6.1.4.1)
|
40
|
+
activesupport (= 6.1.4.1)
|
41
|
+
nokogiri (>= 1.8.5)
|
42
|
+
actionview (6.1.4.1)
|
43
|
+
activesupport (= 6.1.4.1)
|
44
|
+
builder (~> 3.1)
|
45
|
+
erubi (~> 1.4)
|
46
|
+
rails-dom-testing (~> 2.0)
|
47
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
48
|
+
activejob (6.1.4.1)
|
49
|
+
activesupport (= 6.1.4.1)
|
50
|
+
globalid (>= 0.3.6)
|
51
|
+
activemodel (6.1.4.1)
|
52
|
+
activesupport (= 6.1.4.1)
|
53
|
+
activerecord (6.1.4.1)
|
54
|
+
activemodel (= 6.1.4.1)
|
55
|
+
activesupport (= 6.1.4.1)
|
56
|
+
activestorage (6.1.4.1)
|
57
|
+
actionpack (= 6.1.4.1)
|
58
|
+
activejob (= 6.1.4.1)
|
59
|
+
activerecord (= 6.1.4.1)
|
60
|
+
activesupport (= 6.1.4.1)
|
61
|
+
marcel (~> 1.0.0)
|
62
|
+
mini_mime (>= 1.1.0)
|
63
|
+
activesupport (6.1.4.1)
|
64
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
65
|
+
i18n (>= 1.6, < 2)
|
66
|
+
minitest (>= 5.1)
|
67
|
+
tzinfo (~> 2.0)
|
68
|
+
zeitwerk (~> 2.3)
|
69
|
+
ast (2.4.2)
|
70
|
+
awesome_print (1.9.2)
|
71
|
+
builder (3.2.4)
|
72
|
+
byebug (11.1.3)
|
73
|
+
concurrent-ruby (1.1.9)
|
74
|
+
crass (1.0.6)
|
75
|
+
diff-lcs (1.4.4)
|
76
|
+
docile (1.4.0)
|
77
|
+
erubi (1.10.0)
|
78
|
+
globalid (0.5.2)
|
79
|
+
activesupport (>= 5.0)
|
80
|
+
i18n (1.8.10)
|
81
|
+
concurrent-ruby (~> 1.0)
|
82
|
+
loofah (2.12.0)
|
83
|
+
crass (~> 1.0.2)
|
84
|
+
nokogiri (>= 1.5.9)
|
85
|
+
mail (2.7.1)
|
86
|
+
mini_mime (>= 0.1.1)
|
87
|
+
marcel (1.0.1)
|
88
|
+
method_source (1.0.0)
|
89
|
+
mini_mime (1.1.1)
|
90
|
+
mini_portile2 (2.6.1)
|
91
|
+
minitest (5.14.4)
|
92
|
+
nio4r (2.5.8)
|
93
|
+
nokogiri (1.12.4)
|
94
|
+
mini_portile2 (~> 2.6.1)
|
95
|
+
racc (~> 1.4)
|
96
|
+
parallel (1.20.1)
|
97
|
+
parser (3.0.2.0)
|
98
|
+
ast (~> 2.4.1)
|
99
|
+
racc (1.5.2)
|
100
|
+
rack (2.2.3)
|
101
|
+
rack-test (1.1.0)
|
102
|
+
rack (>= 1.0, < 3)
|
103
|
+
rails (6.1.4.1)
|
104
|
+
actioncable (= 6.1.4.1)
|
105
|
+
actionmailbox (= 6.1.4.1)
|
106
|
+
actionmailer (= 6.1.4.1)
|
107
|
+
actionpack (= 6.1.4.1)
|
108
|
+
actiontext (= 6.1.4.1)
|
109
|
+
actionview (= 6.1.4.1)
|
110
|
+
activejob (= 6.1.4.1)
|
111
|
+
activemodel (= 6.1.4.1)
|
112
|
+
activerecord (= 6.1.4.1)
|
113
|
+
activestorage (= 6.1.4.1)
|
114
|
+
activesupport (= 6.1.4.1)
|
115
|
+
bundler (>= 1.15.0)
|
116
|
+
railties (= 6.1.4.1)
|
117
|
+
sprockets-rails (>= 2.0.0)
|
118
|
+
rails-dom-testing (2.0.3)
|
119
|
+
activesupport (>= 4.2.0)
|
120
|
+
nokogiri (>= 1.6)
|
121
|
+
rails-html-sanitizer (1.4.2)
|
122
|
+
loofah (~> 2.3)
|
123
|
+
railties (6.1.4.1)
|
124
|
+
actionpack (= 6.1.4.1)
|
125
|
+
activesupport (= 6.1.4.1)
|
126
|
+
method_source
|
127
|
+
rake (>= 0.13)
|
128
|
+
thor (~> 1.0)
|
129
|
+
rainbow (3.0.0)
|
130
|
+
rake (13.0.6)
|
131
|
+
regexp_parser (2.1.1)
|
132
|
+
rexml (3.2.5)
|
133
|
+
rspec (3.10.0)
|
134
|
+
rspec-core (~> 3.10.0)
|
135
|
+
rspec-expectations (~> 3.10.0)
|
136
|
+
rspec-mocks (~> 3.10.0)
|
137
|
+
rspec-core (3.10.1)
|
138
|
+
rspec-support (~> 3.10.0)
|
139
|
+
rspec-expectations (3.10.1)
|
140
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
141
|
+
rspec-support (~> 3.10.0)
|
142
|
+
rspec-mocks (3.10.2)
|
143
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
144
|
+
rspec-support (~> 3.10.0)
|
145
|
+
rspec-rails (5.0.2)
|
146
|
+
actionpack (>= 5.2)
|
147
|
+
activesupport (>= 5.2)
|
148
|
+
railties (>= 5.2)
|
149
|
+
rspec-core (~> 3.10)
|
150
|
+
rspec-expectations (~> 3.10)
|
151
|
+
rspec-mocks (~> 3.10)
|
152
|
+
rspec-support (~> 3.10)
|
153
|
+
rspec-support (3.10.2)
|
154
|
+
rubocop (1.20.0)
|
155
|
+
parallel (~> 1.10)
|
156
|
+
parser (>= 3.0.0.0)
|
157
|
+
rainbow (>= 2.2.2, < 4.0)
|
158
|
+
regexp_parser (>= 1.8, < 3.0)
|
159
|
+
rexml
|
160
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
161
|
+
ruby-progressbar (~> 1.7)
|
162
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
163
|
+
rubocop-ast (1.11.0)
|
164
|
+
parser (>= 3.0.1.1)
|
165
|
+
ruby-progressbar (1.11.0)
|
166
|
+
simplecov (0.21.2)
|
167
|
+
docile (~> 1.1)
|
168
|
+
simplecov-html (~> 0.11)
|
169
|
+
simplecov_json_formatter (~> 0.1)
|
170
|
+
simplecov-html (0.12.3)
|
171
|
+
simplecov_json_formatter (0.1.3)
|
172
|
+
sprockets (4.0.2)
|
173
|
+
concurrent-ruby (~> 1.0)
|
174
|
+
rack (> 1, < 3)
|
175
|
+
sprockets-rails (3.2.2)
|
176
|
+
actionpack (>= 4.0)
|
177
|
+
activesupport (>= 4.0)
|
178
|
+
sprockets (>= 3.0.0)
|
179
|
+
sqlite3 (1.4.2)
|
180
|
+
thor (1.1.0)
|
181
|
+
tzinfo (2.0.4)
|
182
|
+
concurrent-ruby (~> 1.0)
|
183
|
+
unicode-display_width (2.0.0)
|
184
|
+
websocket-driver (0.7.5)
|
185
|
+
websocket-extensions (>= 0.1.0)
|
186
|
+
websocket-extensions (0.1.5)
|
187
|
+
zeitwerk (2.4.2)
|
188
|
+
|
189
|
+
PLATFORMS
|
190
|
+
ruby
|
191
|
+
|
192
|
+
DEPENDENCIES
|
193
|
+
awesome_print
|
194
|
+
byebug
|
195
|
+
fixturex!
|
196
|
+
rake
|
197
|
+
rspec
|
198
|
+
rspec-rails
|
199
|
+
rubocop
|
200
|
+
simplecov
|
201
|
+
sqlite3
|
202
|
+
|
203
|
+
BUNDLED WITH
|
204
|
+
2.2.27
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 artemave
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Fixturex [![Ruby](https://github.com/artemave/fixturex/actions/workflows/ruby.yml/badge.svg)](https://github.com/artemave/fixturex/actions/workflows/ruby.yml)
|
2
|
+
|
3
|
+
Rails fixtures explorer.
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
Rails fixtures are hard work. There are different sides to that, but one particular thing is that it's not obvious what other fixtures reference the one you're looking at and what fixtures reference those ones referencing the one you're looking at. And so on.
|
8
|
+
|
9
|
+
This little gem to the rescue. It's a command line tool that shows reference tree for a given fixture. It plugs in to vim's quickfix and it shouldn't be too much work to hook it up with vscode, if anyone is up for it.
|
10
|
+
|
11
|
+
<details>
|
12
|
+
<summary>Demo</summary>
|
13
|
+
|
14
|
+
https://user-images.githubusercontent.com/23721/135531049-527640b0-f2f9-436b-923d-c5fc4d9f3fe8.mp4
|
15
|
+
|
16
|
+
</details>
|
17
|
+
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'fixturex'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle install
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install fixturex
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
$ bundle exec fixturex test/fixtures/things.yml thing1
|
38
|
+
|
39
|
+
### Vim
|
40
|
+
|
41
|
+
Here is one way to plug it into vim. Define a new command - let's call it `Fixturex` - in your ([project](https://andrew.stwrt.ca/posts/project-specific-vimrc/)) vimrc:
|
42
|
+
|
43
|
+
```vim
|
44
|
+
command! -nargs=0 Fixturex :cexpr system('bundle exec fixturex '. expand('%') .' '.shellescape(expand('<cword>'))) | copen
|
45
|
+
```
|
46
|
+
|
47
|
+
From then on, if the cursor is on the fixture name in a fixture file, running `:Fixturex` will populate the quickfix window with the reference tree.
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/featurist/fixturex.
|
58
|
+
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'fixturex'
|
6
|
+
require_relative '../spec/dummy/config/environment'
|
7
|
+
require 'active_record/fixtures'
|
8
|
+
|
9
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
10
|
+
# with your gem easier. You can also use a different console, if you like.
|
11
|
+
|
12
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
13
|
+
# require "pry"
|
14
|
+
# Pry.start
|
15
|
+
|
16
|
+
require 'irb'
|
17
|
+
IRB.start(__FILE__)
|
data/bin/fixturex
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Rails runner is hooked into spring an thus the whole thing runs faster
|
5
|
+
IO.popen(['rails', 'runner', File.expand_path('fixturex.rb', __dir__), *ARGV], err: %i[child out]) do |stdout|
|
6
|
+
stdout.each do |line|
|
7
|
+
# Thanks a lot spring. How about an environment variable to silence your bullshit messages?
|
8
|
+
next if line =~ /Running via Spring preloader/
|
9
|
+
|
10
|
+
puts line
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
exit $?.to_i > 0 ? 1 : 0
|
data/bin/fixturex.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require_relative '../lib/fixturex/tree_builder'
|
5
|
+
require 'active_record/fixtures'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.on('-j', '--json', 'output json instead of vimgrep')
|
10
|
+
end.parse!(into: options)
|
11
|
+
|
12
|
+
if ARGV.size != 2
|
13
|
+
puts 'Usage: bundle exec fixturex FIXTURE_PATH FIXTURE_NAME [options]'
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
tree = Fixturex::TreeBuilder.new.build_dependency_tree(Rails.root.join(ARGV[0]), ARGV[1])
|
18
|
+
|
19
|
+
if options[:json]
|
20
|
+
require 'json'
|
21
|
+
puts JSON.generate(tree.to_h)
|
22
|
+
else
|
23
|
+
require_relative '../lib/fixturex/vimgrep_tree_formatter'
|
24
|
+
Fixturex::VimgrepTreeFormatter.new(tree).print
|
25
|
+
end
|
data/bin/setup
ADDED
data/fixturex.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/fixturex/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'fixturex'
|
7
|
+
spec.version = Fixturex::VERSION
|
8
|
+
spec.authors = ['artemave']
|
9
|
+
spec.email = ['mr@artem.rocks']
|
10
|
+
|
11
|
+
spec.summary = 'Rails fixtures explorer'
|
12
|
+
spec.description = 'Generates a tree of "child" fixtures following (deeply) `has_many/has_one` associations.'
|
13
|
+
spec.homepage = 'https://github.com/featurist/fixturex'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
18
|
+
|
19
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
21
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = 'bin'
|
29
|
+
spec.executables = ['fixturex']
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency('rails', '>= 6.0')
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Fixturex
|
2
|
+
class FixtureLocation
|
3
|
+
attr_reader :path, :name
|
4
|
+
|
5
|
+
def initialize(path, name, line = nil)
|
6
|
+
@path = path
|
7
|
+
@name = name
|
8
|
+
@line = line
|
9
|
+
end
|
10
|
+
|
11
|
+
def line
|
12
|
+
@line ||= File.readlines(path).index do |line|
|
13
|
+
line.match?(/^#{name}:/)
|
14
|
+
end + 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_h
|
18
|
+
{
|
19
|
+
name: name,
|
20
|
+
path: path.to_s,
|
21
|
+
line: line
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require_relative './tree_entry'
|
5
|
+
require_relative './fixture_location'
|
6
|
+
|
7
|
+
module Fixturex
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
# Fixtures for model class
|
11
|
+
class ModelFixtures
|
12
|
+
Fixture = Struct.new(:name, :path, :attributes)
|
13
|
+
|
14
|
+
def self.load(class_name)
|
15
|
+
fixtures_paths(class_name).each_with_object([]) do |path, acc|
|
16
|
+
fixtures = YAML.load_file(path)
|
17
|
+
fixtures.select! do |_name, attributes|
|
18
|
+
# if fixture has `type` - STI - then we only want type == class_name
|
19
|
+
attributes['type'].nil? || attributes['type'] == class_name
|
20
|
+
end
|
21
|
+
acc.concat(fixtures.map { |name, attributes| Fixture.new(name, path, attributes) })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.fixtures_paths(class_name)
|
26
|
+
fixtures_paths = []
|
27
|
+
klass = class_name.constantize
|
28
|
+
# TODO: is there a better way to find out fixtures root directory?
|
29
|
+
fixtures_root = ActiveRecord::Tasks::DatabaseTasks.fixtures_path
|
30
|
+
|
31
|
+
while klass < ActiveRecord::Base
|
32
|
+
fixture_file = "#{klass.to_s.tableize}.yml"
|
33
|
+
path = File.join(fixtures_root, *fixture_file.split('/'))
|
34
|
+
|
35
|
+
fixtures_paths << path if File.exist?(path)
|
36
|
+
|
37
|
+
klass = klass.superclass
|
38
|
+
end
|
39
|
+
fixtures_paths
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
FixtureModel = Struct.new(:fixture_path) do
|
44
|
+
def model_class
|
45
|
+
# TODO: support custom model_class from yaml
|
46
|
+
# TODO: support (or document the limitation) `set_fixture_class my_products: Product`
|
47
|
+
ActiveRecord::FixtureSet.default_fixture_model_name(fixture_set).constantize
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def fixture_set
|
53
|
+
fixture_path.to_s.sub(%r{^.*/fixtures/}, '').sub('.yml', '')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class TreeBuilder
|
58
|
+
def build_dependency_tree(fixture_path, fixture_name)
|
59
|
+
TreeEntry.new(
|
60
|
+
FixtureLocation.new(fixture_path, fixture_name),
|
61
|
+
nested_fixtures_locations(FixtureModel.new(fixture_path).model_class, fixture_name)
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def nested_fixtures_locations(parent_fixture_model_class, parent_fixture_name)
|
68
|
+
associations_for_nested_models(parent_fixture_model_class).each_with_object([]) do |association, acc|
|
69
|
+
belongs_to_attribute = belongs_to_attribute_for_association(association)
|
70
|
+
model_fixtures = ModelFixtures.load(association.class_name)
|
71
|
+
|
72
|
+
model_fixtures.each do |fixture|
|
73
|
+
next if fixture.attributes.fetch(belongs_to_attribute, '').to_s.sub(/ .*/, '') != parent_fixture_name
|
74
|
+
|
75
|
+
next if fixture_already_collected(acc, fixture)
|
76
|
+
|
77
|
+
acc << build_dependency_tree(fixture.path, fixture.name)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def fixture_already_collected(list, fixture)
|
83
|
+
list.find do |tree_entry|
|
84
|
+
tree_entry.value.path == fixture.path && tree_entry.value.name == fixture.name
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def associations_for_nested_models(model_class)
|
89
|
+
model_class.reflect_on_all_associations(:has_many) +
|
90
|
+
model_class.reflect_on_all_associations(:has_one)
|
91
|
+
end
|
92
|
+
|
93
|
+
def belongs_to_attribute_for_association(association)
|
94
|
+
if association.type.present?
|
95
|
+
association.type.sub('_type', '')
|
96
|
+
else
|
97
|
+
association.active_record.name.tableize.singularize
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fixturex
|
4
|
+
class VimgrepTreeFormatter
|
5
|
+
def initialize(tree, stdout = $stdout)
|
6
|
+
@tree = tree
|
7
|
+
@stdout = stdout
|
8
|
+
end
|
9
|
+
|
10
|
+
def print
|
11
|
+
print_entry(@tree, '', file_address_lengths(@tree).max)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def print_entry(entry, indent, file_address_column_size)
|
17
|
+
offset = file_address_column_size - file_address(entry).size
|
18
|
+
|
19
|
+
@stdout.puts "#{file_address(entry)}#{Array.new(offset).map { ' ' }.join} #{indent}#{entry.value.name}"
|
20
|
+
entry.children.each do |child_entry|
|
21
|
+
print_entry(child_entry, "#{indent} ", file_address_column_size)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def file_address_lengths(entry)
|
26
|
+
[
|
27
|
+
file_address(entry).size
|
28
|
+
].concat(
|
29
|
+
entry.children.map { |e| file_address_lengths(e) }
|
30
|
+
).flatten
|
31
|
+
end
|
32
|
+
|
33
|
+
def file_address(entry)
|
34
|
+
"#{entry.value.path}:#{entry.value.line}:1"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/fixturex.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fixturex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- artemave
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-10-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.0'
|
27
|
+
description: Generates a tree of "child" fixtures following (deeply) `has_many/has_one`
|
28
|
+
associations.
|
29
|
+
email:
|
30
|
+
- mr@artem.rocks
|
31
|
+
executables:
|
32
|
+
- fixturex
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".github/workflows/ruby.yml"
|
37
|
+
- ".gitignore"
|
38
|
+
- ".travis.yml"
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/fixturex
|
46
|
+
- bin/fixturex.rb
|
47
|
+
- bin/setup
|
48
|
+
- fixturex.gemspec
|
49
|
+
- lib/fixturex.rb
|
50
|
+
- lib/fixturex/fixture_location.rb
|
51
|
+
- lib/fixturex/tree_builder.rb
|
52
|
+
- lib/fixturex/tree_entry.rb
|
53
|
+
- lib/fixturex/version.rb
|
54
|
+
- lib/fixturex/vimgrep_tree_formatter.rb
|
55
|
+
homepage: https://github.com/featurist/fixturex
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 2.3.0
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.1.6
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Rails fixtures explorer
|
78
|
+
test_files: []
|