Sha256: f23a446a8fe5868238b5f15eec25e55a3371bd6abfb84b6b0fead34910e7b651

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module Superhosting
  module MapperInheritance
    class Mux
      include Base

      def initialize(mapper)
        super()
        @mapper = mapper
        @muxs_mapper = @mapper.parent
        self.collect_inheritors
      end

      def set_inheritors(mapper=@mapper)
        raise NetStatus::Exception, { error: :input_error, code: :mux_does_not_exists, data: { name: mapper.name } } unless mapper.dir?
        raise NetStatus::Exception, { error: :logical_error, code: :base_mux_should_not_be_abstract, data: { name: mapper.name } } if mapper.abstract?
        super(mapper)
      end

      def collect_inheritors(m=@mapper, depth=0)
        depth += 1

        m.inherit.lines.each do |name|
          inherit_mapper = @muxs_mapper.f(name)
          raise NetStatus::Exception, { error: :logical_error, code: :mux_does_not_exists, data: { name: name } } unless inherit_mapper.dir?

          collect_inheritors(inherit_mapper, depth)
        end

        collect_inheritor(m, depth) unless m == @mapper
      end

      def collect_inheritor(mapper, depth)
        (self.inheritors[depth] ||= []) << mapper
      end

      def set_inheritance(mapper)
        self.inheritors.sort.each do |k, inheritors|
          inheritors.each do |inheritor|
            if inheritor.dir?
              inheritor.changes_overlay = mapper
              mapper << inheritor
            end
          end
        end
        mapper
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
superhosting-0.0.2 lib/superhosting/mapper_inheritance/mux.rb