Class: Superhosting::MapperInheritance::Model
- Inherits:
-
Object
- Object
- Superhosting::MapperInheritance::Model
- Includes:
- Base
- Defined in:
- lib/superhosting/mapper_inheritance/model.rb
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
- #collect_inheritor(mapper, depth, mux) ⇒ Object
- #collect_inheritors(m = @model_mapper, depth = 0, mux = false) ⇒ Object
- #collect_inheritors_tree(m = @model_mapper, node = self.inheritors_tree, mux = false) ⇒ Object
-
#initialize(model_mapper) ⇒ Model
constructor
A new instance of Model.
- #set_inheritance(mapper) ⇒ Object
- #set_inheritors(mapper) ⇒ Object
Constructor Details
#initialize(model_mapper) ⇒ Model
Returns a new instance of Model.
6 7 8 9 10 11 12 |
# File 'lib/superhosting/mapper_inheritance/model.rb', line 6 def initialize(model_mapper) super() @model_mapper = model_mapper @models_mapper = @model_mapper.parent @muxs_mapper = @models_mapper.parent.muxs self.collect_inheritors end |
Instance Method Details
#collect_inheritor(mapper, depth, mux) ⇒ Object
76 77 78 79 |
# File 'lib/superhosting/mapper_inheritance/model.rb', line 76 def collect_inheritor(mapper, depth, mux) self.inheritors[depth] ||= {} (self.inheritors[depth][mux ? 'mux' : 'model'] ||= []) << mapper end |
#collect_inheritors(m = @model_mapper, depth = 0, mux = false) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/superhosting/mapper_inheritance/model.rb', line 27 def collect_inheritors(m=@model_mapper, depth=0, mux=false) depth += 1 # mux m.container.mux.lines.each do |name| mux_mapper = @muxs_mapper.f(name) raise NetStatus::Exception, { error: :logical_error, code: :base_mux_should_not_be_abstract, data: { name: name } } if mux_mapper.abstract? raise NetStatus::Exception, { error: :logical_error, code: :mux_does_not_exists, data: { name: name } } unless mux_mapper.dir? collect_inheritors(mux_mapper, depth, true) end m.inherit.lines.each do |name| inherit_mapper = (mux ? @muxs_mapper : @models_mapper).f(name) raise NetStatus::Exception, { error: :logical_error, code: :model_does_not_exists, data: { name: name } } unless inherit_mapper.dir? # mixed collect_inheritors(inherit_mapper, depth, mux) end # model collect_inheritor(m, depth, mux) depth end |
#collect_inheritors_tree(m = @model_mapper, node = self.inheritors_tree, mux = false) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/superhosting/mapper_inheritance/model.rb', line 52 def collect_inheritors_tree(m=@model_mapper, node=self.inheritors_tree, mux=false) type = mux ? 'mux' : 'model' node[m] ||= {} node[m][type] ||= [] # mux m.container.mux.lines.each do |name| mux_mapper = @muxs_mapper.f(name) raise NetStatus::Exception, { error: :logical_error, code: :base_mux_should_not_be_abstract, data: { name: name } } if mux_mapper.abstract? raise NetStatus::Exception, { error: :logical_error, code: :mux_does_not_exists, data: { name: name } } unless mux_mapper.dir? (node[m]['mux'] ||= []) << collect_inheritors_tree(mux_mapper, {}, true) end m.inherit.lines.each do |name| inherit_mapper = (mux ? @muxs_mapper : @models_mapper).f(name) raise NetStatus::Exception, { error: :logical_error, code: :model_does_not_exists, data: { name: name } } unless inherit_mapper.dir? # mixed node[m][mux ? 'mux' : 'model'] << collect_inheritors_tree(inherit_mapper, {}, mux) end node end |
#set_inheritance(mapper) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/superhosting/mapper_inheritance/model.rb', line 81 def set_inheritance(mapper) self.inheritors.sort.each do |k, inherits| %w(mux model).each do |t| (inherits[t] || []).each do |inheritor| if (type_dir_mapper = inheritor.f(@type)).dir? type_dir_mapper. = mapper mapper << type_dir_mapper end end end end mapper end |
#set_inheritors(mapper) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/superhosting/mapper_inheritance/model.rb', line 14 def set_inheritors(mapper) raise NetStatus::Exception, { error: :input_error, code: :model_does_not_exists, data: { name: @model_mapper.name } } unless @model_mapper.dir? raise NetStatus::Exception, { error: :logical_error, code: :base_model_should_not_be_abstract, data: { name: @model_mapper.name } } if @model_mapper.abstract? @type = case type = mapper.parent.name when 'containers' then 'container' when 'sites' then 'site' else raise NetStatus::Exception, { error: :logical_error, code: :mapper_type_not_supported, data: { name: type } } end super(mapper) end |