Reputation: 16629
I want to write a ruby script to list the names and their attributes of factories in a project (with factory girl
).
My problem is, I'm not sure how can I determine the start
and end
of a given factory
The approach I'm thinking is to,
factory
, I assume its the starting of a
factory. (and I get the starting position)end
and if it is in align
with the factory
I assume its the end of the factoryBut the downside of this is, If the alignments are different I will not be able to determine the end point of the factory.
My questions are,
I checked rubocop
, and their approach to handle alignments, but seems like since its a general approach, its complicated. I believe their should be an easier way.
Upvotes: 1
Views: 592
Reputation: 2732
If you need to actually parse the factories.rb
file and can't just execute the Ruby, I'd strongly recommend using a true parser like Ripper instead of writing a string parser for Ruby yourself.
Upvotes: 1
Reputation: 311605
That seems like quite a bit of overkill. You can just ask FactoryGirl itself, since each Factory
has an attributes
object and name associated with it.
Upvotes: 1