Official support for ActiveSupport::Duration w/o core extensions

88 views
Skip to first unread message

Steve Jorgensen

unread,
Mar 21, 2015, 4:47:59 PM3/21/15
to rubyonra...@googlegroups.com
I'm not sure if this is the right place to ask about this, so my apologies if it is not.

I am interested in writing a Gem that takes advantage of ActiveSupport durations, but I don't want to require using core extensions in order to use my gem. I notice that there is a ActiveSupport::Duration class that I can use, but its constructor is not documented. That makes me feel that if to rely on it is to rely on an unpublished interface.

Would it make sense for me to submit a PR to add documentation for ActiveSupport::Duration constructor to make it more of an officially supported thing?

Nicolás Sanguinetti

unread,
Mar 21, 2015, 5:00:12 PM3/21/15
to rubyonra...@googlegroups.com, rubyonra...@googlegroups.com
By requiring "active_support/duration" you’re already forcing core extensions on your users. Take a look at https://github.com/rails/rails/blob/master/activesupport/lib/active_support/duration.rb#L1-L2

(And if you look at those files, they in turn require even more things from core_ext).

You might not be adding Integer#hours et al, but a bunch of other things are being added on Hash, Array, String…

Cheers,
-foca




--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Steve Jorgensen

unread,
Mar 21, 2015, 5:13:34 PM3/21/15
to rubyonra...@googlegroups.com
Thanks for pointing that out. My question is apparently moot, then.

Is there any desire to see ActiveSupport refactored such that more of its functionality is available without having to use core extensions?

Andrey Novikov

unread,
Mar 22, 2015, 9:04:31 AM3/22/15
to rubyonra...@googlegroups.com
Take a look to ISO8601 gem: https://github.com/arnau/ISO8601 It have durations as well.

Steve Jorgensen

unread,
Mar 22, 2015, 1:46:23 PM3/22/15
to rubyonra...@googlegroups.com
Thanks. I did not know about that gem. Looks very interesting (except for the use of floats for seconds <slight cringe>). The main reason I had been aiming for the use of ActiveSupport durations is because that makes it easier to cleanly integrate into Rails apps and the multitude of other apps that are using ActiveSupport already.

Andrey Novikov

unread,
Mar 22, 2015, 4:25:57 PM3/22/15
to rubyonra...@googlegroups.com
ActiveSupport::Duration uses floats for seconds too (if needed, try to execute 4.2.seconds in rails console). Few versions ago durations were (and still are) auxiliary things. Currently I'm trying to make them more self-sufficient in #16917 and #16919, but review process seems to be endless. So, I think it's good idea to document constructor. Or may be even change it (now you should know all the parts and calculate their value in seconds to construct duration — inconvenient), but this requires consulting with someone from core team.

P.S> If you're already using Active Support why do you ever worrying about core extensions? You have all of them already switched on in Rails app by default.

--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/_SZykxCFVYk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-co...@googlegroups.com.

Steve Jorgensen

unread,
Mar 22, 2015, 5:00:06 PM3/22/15
to rubyonra...@googlegroups.com
I'm hoping to target the gem for a somewhat broader audience than just my current requirement.

Steve Jorgensen

unread,
Mar 22, 2015, 5:08:49 PM3/22/15
to rubyonra...@googlegroups.com
…but I think I've decided to just layer on top of ActiveSupport as is-for now, core extensions, and all.
Reply all
Reply to author
Forward
0 new messages