Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add 'quantity/rails' compatibility patch

* overrides `method_missing` to check if equivalent quantity
  object responds to the method
  • Loading branch information...
commit f646f934d865ca1d69f9164b7db2b330195111fe 1 parent 62794c3
@mtodd mtodd authored
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/quantity/rails.rb
View
12 lib/quantity/rails.rb
@@ -0,0 +1,12 @@
+ActiveSupport::Duration.class_eval do
+ def quantity
+ Quantity.new(@value, Quantity::Unit.for(:second))
+ end
+
+ def method_missing_with_quantity(method, *args, &block) #:nodoc:
+ return quantity.send(method, *args, &block) if quantity.respond_to?(method)
+
+ method_missing_without_quantity(method, *args, &block)
+ end
+ alias_method_chain :method_missing, :quantity
+end
Please sign in to comment.
Something went wrong with that request. Please try again.