Suggestion: Replace your implementation of `Faker::String.from_regexp` with a dependency · Issue #328 · ffaker/ffaker · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently stumbled across this gem, and noticed that you are using a custom implementation of Faker::String.from_regexp to generate strings from a regular expression:
This implementation is OK for the basics, but is far from comprehensive! There is an open issue about one such bug, and another open issue that's apparently unresolved.
The regexp language is vast and complicated; solving this problem for all possible regular expressions is far from easy. However, this library provides a much more complete solution. For backwards compatibility, you could implement this as:
module FFaker
module String
def self.from_regexp(exp)
puts 'Warning: FFaker::String.from_regexp is deprecated. Use exp.random_example'
exp.random_example
end
end
end
There are a couple of potential minor issues we could discuss before dropping in this replacement (e.g. Regexp#random_example could be a refinement instead of a global class extension?), but more the most part it should be a very simple change.
The text was updated successfully, but these errors were encountered:
Hello, just a random guy here looking to contribute.
In my opinion, improved support for FFaker::String.from_regexp could theoretically help easily resolve issues such as #353. In this case one would simply plug in a valid regex and wrap it in a method.
I am personally opposed to any sort of monkey patching in cases where it can otherwise be avoided, so if a dependency is to be introduced, I would recommend that the gem has its own namespace. Then FFaker::String.from_regexp could in theory be simply re-implemented as:
module FFaker::String
def self.from_regexp(exp)
RegexpToRandomString.generate(exp)
end
end
Uh oh!
There was an error while loading. Please reload this page.
I recently stumbled across this gem, and noticed that you are using a custom implementation of
Faker::String.from_regexp
to generate strings from a regular expression:ffaker/lib/ffaker/string.rb
Lines 19 to 28 in 49d2226
This implementation is OK for the basics, but is far from comprehensive! There is an open issue about one such bug, and another open issue that's apparently unresolved.
The regexp language is vast and complicated; solving this problem for all possible regular expressions is far from easy. However, this library provides a much more complete solution. For backwards compatibility, you could implement this as:
There are a couple of potential minor issues we could discuss before dropping in this replacement (e.g.
Regexp#random_example
could be a refinement instead of a global class extension?), but more the most part it should be a very simple change.The text was updated successfully, but these errors were encountered: