Sha256: 305950b44966ac9eab5bac6732c8e9136101a292e1e6eb3e53cf46775c7ecc6b
Contents?: true
Size: 788 Bytes
Versions: 2
Compression:
Stored size: 788 Bytes
Contents
module ActiveMocker class CollectionAssociation include Enumerable def initialize(collection=[]) @association = [*collection] end def <<(*records) association.concat(records.flatten) end delegate :any?, :empty?, :length, :size, :count, :uniq, :replace, :first, :last, :concat, :include?, :push, :clear, :take, to: :association alias distinct uniq def sum(attribute=nil) values = association.map { |obj| obj.send(attribute) } values.inject { |sum, n| sum + n } end def ==(other_ary) association == other_ary end def each(&block) association.each do |item| block.call(item) end end def to_a @association end private attr_accessor :association end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_mocker-1.2.4 | lib/active_mocker/collection_association.rb |
active_mocker-1.2.3 | lib/active_mocker/collection_association.rb |