Sha256: 3712495609c0738f8a54e3cf00e20f341865ca08eb50281442490741a1ed3142

Contents?: true

Size: 813 Bytes

Versions: 4

Compression:

Stored size: 813 Bytes

Contents

class SiteHub
  class Collection < Hash
    class DuplicateVersionError < StandardError
    end

    module ClassMethods
      def overrides
        @overrides ||= []
      end

      UNIQUE_LABELS_MSG = 'supply unique labels'.freeze

      def method_added(name)
        if name == :add && !overrides.include?(name)
          overrides << name
          alias_method :add_backup, :add

          send(:define_method, :add) do |id, value, *args|
            raise DuplicateVersionError, UNIQUE_LABELS_MSG if key?(id)
            add_backup id, value, *args
          end
        end
      end
    end

    def valid?
      raise 'implement me'
    end

    def resolve
      raise 'implement me'
    end

    class << self
      def inherited(clazz)
        clazz.extend(ClassMethods)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sitehub-0.5.0.alpha12 lib/sitehub/collection.rb
sitehub-0.5.0.alpha11 lib/sitehub/collection.rb
sitehub-0.5.0.alpha10 lib/sitehub/collection.rb
sitehub-0.5.0.alpha8 lib/sitehub/collection.rb