Sha256: 2d53cd6bd67dddbd487b66fbb6dd24b208d7017f51deb661070d93026c882f2b

Contents?: true

Size: 706 Bytes

Versions: 1

Compression:

Stored size: 706 Bytes

Contents

module ActiveEnumerable
  module Base
    def initialize(collection=[])
      @to_a = collection.to_ary
    end

    attr_reader :to_a

    # @private
    def __new_relation__(collection)
      self.class.new(collection)
    end

    def create(attributes)
      add(if (klass = self.class.item_class)
            klass.new(attributes)
          else
            attributes
          end)
    end

    def add(item)
      to_a << item
    end

    def all
      self
    end

    module ClassMethods
      def item_class
        @item_class
      end

      def item_class=(klass)
        @item_class = klass
      end
    end

    def self.included(base)
      base.extend(ClassMethods)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_enumerable-0.1.1 lib/active_enumerable/base.rb