Sha256: dc787aedcd430afdb87ecaae3d9bf5f6276a310d9f43f0002580ac202dd84a7d

Contents?: true

Size: 739 Bytes

Versions: 2

Compression:

Stored size: 739 Bytes

Contents

class SiteHub
  class Collection < Hash
    class DuplicateVersionException < Exception;
    end

    def valid?
      raise "implement me"
    end

    def resolve
      raise "implement me"
    end

    class << self
      def inherited clazz

        def clazz.overrides
          @overrides ||=[]
        end

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

            self.send(:define_method, :add) do |id, value, *args|
              raise DuplicateVersionException, 'supply unique labels' if self[id]
              add_backup id, value, *args
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sitehub-0.4.2 lib/sitehub/collection.rb
sitehub-0.4.1 lib/sitehub/collection.rb