Class: ActsPermissive::Circling
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActsPermissive::Circling
- Defined in:
- lib/acts_permissive/circling.rb
Class Method Summary collapse
-
.items_in(circle) ⇒ Object
Return all items in the circle.
Class Method Details
.items_in(circle) ⇒ Object
Return all items in the circle. Not that this could simply be done with the one line
where(:circle_id => circle.id).map{|c| c.circleable}.compact
if we were not allowing ActiveResource associations in our circles. However, given that we are, ActiveResource models have no way to automatically translate from ‘circleable’ to the model because they are missing the ‘scoped’ method. Thus, we catch that no method error and instantiate the model manually. It’s possible we could do this by opening ActiveResource, but I thought this was less intrusive
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/acts_permissive/circling.rb', line 20 def items_in circle lst = where(:circle_id => circle.id).map do |c| begin c.circleable rescue NoMethodError c.circleable_type.constantize.find(c.circleable_id) end end lst.compact end |