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
Set up config_accessor with a default value by block #7645
Conversation
It seems ok to me, although I don't see a real gain from one over another: config_accessor :hair_colors do
[:brown, :black, :blonde, :red]
end
# vs
config_accessor :hair_colors
self.hair_colors = [:brown, :black, :blonde, :red] In any case, your pull request needs a changelog entry as well. Thanks! |
@carlosantoniodasilva I have updated ActiveSuppport's CHANGELOG. |
@larrylv : just rebase your commits squashing them into a single one. :) |
@robin850 then do I have to open another pull request or just |
@larrylv : once your commits are squashed, just push with |
@robin850 Thx. Already done that. :-) |
I allow myself to ping @carlosantoniodasilva to merge this. ^^ |
@carlosantoniodasilva Sorry, my mistake. Already moved changelog entry to the top. |
Great! Now github is telling me: This pull request cannot be automatically merged.. I think you'll need to rebase :) |
* ActiveSupport::Configurable should allow config_accessor to take default value by block, just like cattr_accessor. class User include ActiveSupport::Configurable config_accessor :hair_colors do [:brown, :black, :blonde, :red] end end User.hair_colors # => [:brown, :black, :blonde, :red] * remove trailing whitespaces in configurable.rb and its test file. * Update ActiveSupport CHANGELOG.
@carlosantoniodasilva Done with rebase. Please check it out. :) |
Set up config_accessor with a default value by block
Thanks. |
I am curious about why use block to define default value.The
|
@zires I don't think
And the reason I choose to use block to define default value is In some way, they are very alike. |
I think a block to always define a default value is weird (and more expensive). Why not have a default: key? |
@bobbytables That is what i mean |
AS::Configurable's `config_accessor` supports a default block only since rails 4 -- see rails/rails#7645.
AS::Configurable's `config_accessor` supports a default block only since rails 4 -- see rails/rails#7645.
ActiveSupport::Configurable should allow config_accessor to take
default value by block, just like
cattr_accessor
.remove trailing whitespaces in configurable.rb and its test file.
It's an old pull request #5730, but no one implement it . I just implement it like someone suggested, change the interface to just like
cattr_accessor
.