Sha256: d37691d433e547a582c4950275932834a6d3a63a0d2b2b0b9996605ba992ca74
Contents?: true
Size: 1.27 KB
Versions: 2
Compression:
Stored size: 1.27 KB
Contents
module EdgeRider module CollectIds class Uncollectable < StandardError; end module Array def collect_ids collect do |obj| case obj when Integer obj when ActiveRecord::Base obj.id when String if obj.match(/\A\d+\z/) obj.to_i else raise Uncollectable, "Cannot collect an id from #{obj.inspect}" end else raise Uncollectable, "Cannot collect an id from #{obj.inspect}" end end end end ::Array.send(:include, Array) module ActiveRecordValue def collect_ids [id] end end module ActiveRecordScope def collect_ids collect_column(:id) end end module Integer def collect_ids [self] end end ::Integer.send(:include, Integer) end end ActiveSupport.on_load :active_record do extend(EdgeRider::CollectIds::ActiveRecordScope) include(EdgeRider::CollectIds::ActiveRecordValue) ActiveRecord::Associations::HasManyAssociation.send(:include, EdgeRider::CollectIds::ActiveRecordScope) ActiveRecord::Associations::HasManyThroughAssociation.send(:include, EdgeRider::CollectIds::ActiveRecordScope) end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
edge_rider-2.4.0 | lib/edge_rider/collect_ids.rb |
edge_rider-2.3.1 | lib/edge_rider/collect_ids.rb |