Class: Fiona7::TypeRegister::TypeDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/fiona7/type_register.rb

Defined Under Namespace

Classes: Attribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ TypeDefinition

Returns a new instance of TypeDefinition.



60
61
62
63
64
# File 'lib/fiona7/type_register.rb', line 60

def initialize(name)
  self.name = name
  self.real_name = Fiona7::ObjClassNameMangler.new(name).mangle
  self.attrs = Set.new
end

Instance Attribute Details

#aliaserObject

Returns the value of attribute aliaser.



58
59
60
# File 'lib/fiona7/type_register.rb', line 58

def aliaser
  @aliaser
end

#attrsObject

Returns the value of attribute attrs.



57
58
59
# File 'lib/fiona7/type_register.rb', line 57

def attrs
  @attrs
end

#nameObject

Returns the value of attribute name.



55
56
57
# File 'lib/fiona7/type_register.rb', line 55

def name
  @name
end

#real_nameObject

Returns the value of attribute real_name.



56
57
58
# File 'lib/fiona7/type_register.rb', line 56

def real_name
  @real_name
end

Instance Method Details

#add_attr(name, type, real_name = nil, real_type = nil, values = nil) ⇒ Object



71
72
73
74
75
# File 'lib/fiona7/type_register.rb', line 71

def add_attr(name, type, real_name=nil, real_type=nil, values=nil)
  real_type ||= Fiona7::AttributeTypeMapper.new(self.name.to_s).call(name.to_sym, type.to_sym)
  real_name = Fiona7::AttributeNameMangler.new(name, self.name).mangle
  self.attrs << Attribute.new(name.to_s, type.to_sym, real_name.to_s, real_type.to_sym, values)
end

#find_attribute(name) ⇒ Object



77
78
79
80
81
82
# File 'lib/fiona7/type_register.rb', line 77

def find_attribute(name)
  name = name.to_s
  self.attrs.find do |attr|
    attr.name == name
  end
end

#merge(other_definition) ⇒ Object

TODO: conflict handling for type errors



92
93
94
95
96
97
98
99
# File 'lib/fiona7/type_register.rb', line 92

def merge(other_definition)
  other_definition.attrs.each do |other_attr|
    if !self.attrs.include?(other_attr)
      self.attrs << other_attr
    end
  end
  self
end

#remove_attribute(name) ⇒ Object



84
85
86
87
88
89
# File 'lib/fiona7/type_register.rb', line 84

def remove_attribute(name)
  name = name.to_s
  self.attrs.delete_if do |attr|
    attr.name == name
  end
end

#virtual_nameObject



67
68
69
# File 'lib/fiona7/type_register.rb', line 67

def virtual_name
  self.name
end