Module: UniverseCompiler::Entity::Inheritance

Extended by:
FieldBinder
Included in:
Base
Defined in:
lib/universe_compiler/entity/inheritance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FieldBinder

field_accessor, field_reader, field_writer

Instance Attribute Details

#compiledObject (readonly)

Returns the value of attribute compiled.



9
10
11
# File 'lib/universe_compiler/entity/inheritance.rb', line 9

def compiled
  @compiled
end

Instance Method Details

#apply_inheritanceObject



11
12
13
14
15
16
17
18
19
# File 'lib/universe_compiler/entity/inheritance.rb', line 11

def apply_inheritance
  return unless compiled.nil?
  unless extends.nil?
    valid_for_inheritance? raise_error: true
    @fields = fields_inheritance_result
  end
ensure
  @compiled = true
end

#valid_for_inheritance?(raise_error: false) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/universe_compiler/entity/inheritance.rb', line 21

def valid_for_inheritance?(raise_error: false)
  is_valid = true
  unless extends.nil?
    is_valid = false
    if extends.respond_to? :type and extends.respond_to? :name
      if extends.respond_to? :fields or extends.is_a? UniverseCompiler::Entity::Reference
        is_valid = self.type == extends.type
      end
    end
  end
  return true if is_valid
  false_or_raise "Invalid entity '#{to_composite_key}' ! Inheritance is invalid !", raise_error: raise_error
end