Sha256: 0fb00a315b9344c1d466ecec0c1546e4c1da2f92c430e6dfc1ad5367e1a44a5d

Contents?: true

Size: 838 Bytes

Versions: 5

Compression:

Stored size: 838 Bytes

Contents

module EdgeRider
  module CollectIds

    class Uncollectable < StandardError; end

    module Array

      def collect_ids
        collect do |obj|
          case obj
            when Fixnum then obj
            when ActiveRecord::Base then obj.id
            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

    ::ActiveRecord::Base.send(:include, ActiveRecordValue)

    module ActiveRecordScope

      def collect_ids
        collect_column(:id)
      end

    end

    ::ActiveRecord::Base.send(:extend, ActiveRecordScope)

    module Fixnum

      def collect_ids
        [self]
      end

    end

    ::Fixnum.send(:include, Fixnum)

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
edge_rider-0.2.3 lib/edge_rider/collect_ids.rb
edge_rider-0.2.2 lib/edge_rider/collect_ids.rb
edge_rider-0.2.1 lib/edge_rider/collect_ids.rb
edge_rider-0.2.0 lib/edge_rider/collect_ids.rb
edge_rider-0.1.1 lib/edge_rider/collect_ids.rb