Freshly/spicerack

View on GitHub
collectible/lib/collectible/collection/core.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module Collectible
  module Collection
    module Core
      extend ActiveSupport::Concern

      included do
        attr_reader :items

        delegate :name, to: :class, prefix: true
        delegate :include?, :to_a, :to_ary, :select, :map, :group_by, :partition, :as_json, to: :items
      end

      def initialize(*items)
        @items = items.flatten
      end

      def hash
        { class_name: class_name, items: items }.hash
      end
    end
  end
end