Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STI will not pick up custom generator #15

Open
equivalent opened this issue Dec 17, 2018 · 1 comment
Open

STI will not pick up custom generator #15

equivalent opened this issue Dec 17, 2018 · 1 comment
Labels

Comments

@equivalent
Copy link
Owner

This works:

Foo < ActiveRecord::Base
     generate_public_uid generator: PublicUid::Generators::HexStringSecureRandom.new(50)
end

foo = Foo.new
foo.save!
foo.public_uid.length # => 50

this wil not


```ruby
Bar <Foo
end

foo = Foo.new
foo.save!
foo.public_uid.length # => 8

due to https://github.com/equivalent/public_uid/blob/master/lib/public_uid/model.rb#L25 instance method set the config is not copied across inheritance which is bad in this case

possible solution: use class variables @@generator =

@equivalent
Copy link
Owner Author

equivalent commented Dec 17, 2018

🤔 or inherited hook will be more OOP way https://www.sitepoint.com/rubys-important-hook-methods/

update

on second tought that causes lot of errors on Rails as Rails does some weird reloads on inheritance

@equivalent equivalent added the bug label Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant