Class: Superhosting::MapperInheritance::Mux

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/superhosting/mapper_inheritance/mux.rb

Instance Attribute Summary

Attributes included from Base

#inheritors, #inheritors_tree

Instance Method Summary collapse

Constructor Details

#initialize(mapper) ⇒ Mux

Returns a new instance of Mux.



6
7
8
9
10
11
# File 'lib/superhosting/mapper_inheritance/mux.rb', line 6

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

Instance Method Details

#collect_inheritor(mapper, depth) ⇒ Object



32
33
34
# File 'lib/superhosting/mapper_inheritance/mux.rb', line 32

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

#collect_inheritors(m = @mapper, depth = 0) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/superhosting/mapper_inheritance/mux.rb', line 19

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

#set_inheritance(mapper) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/superhosting/mapper_inheritance/mux.rb', line 36

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

#set_inheritors(mapper = @mapper) ⇒ Object

Raises:

  • (NetStatus::Exception)


13
14
15
16
17
# File 'lib/superhosting/mapper_inheritance/mux.rb', line 13

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