Module: UniverseCompiler::Entity::Conversion

Included in:
Base, Reference
Defined in:
lib/universe_compiler/entity/conversion.rb

Instance Method Summary collapse

Instance Method Details

#==(another_reference) ⇒ Object



27
28
29
30
# File 'lib/universe_compiler/entity/conversion.rb', line 27

def ==(another_reference)
  return false unless another_reference.respond_to? :to_composite_key
  to_composite_key == another_reference.to_composite_key
end

#as_pathObject



8
9
10
# File 'lib/universe_compiler/entity/conversion.rb', line 8

def as_path
  to_composite_key.map(&:to_s).join '/'
end

#encode_with(coder) ⇒ Object



49
50
51
52
53
# File 'lib/universe_compiler/entity/conversion.rb', line 49

def encode_with(coder)
  dereferenced_fields.each do |key, value|
    coder[key] = value
  end
end

#eql?(another_reference) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/universe_compiler/entity/conversion.rb', line 32

def eql?(another_reference)
  self == another_reference and universe == another_reference.universe
end

#init_with(coder) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/universe_compiler/entity/conversion.rb', line 55

def init_with(coder)
  initialize
  self.fully_resolved = false
  coder.map.each do |key, value|
    self[key] = value
  end
end

#inspectObject



20
21
22
23
24
25
# File 'lib/universe_compiler/entity/conversion.rb', line 20

def inspect
  msg = "#<#{self.class.name}:#{object_id} composite_key=#{to_composite_key.inspect}"
  msg << ", @universe='#{universe.name}'" unless universe.nil?
  msg << '>'
  msg
end

#to_composite_keyObject



12
13
14
# File 'lib/universe_compiler/entity/conversion.rb', line 12

def to_composite_key
  [type, name]
end

#to_hashObject



36
37
38
39
40
41
42
43
# File 'lib/universe_compiler/entity/conversion.rb', line 36

def to_hash
  {
      self.class.name => {
          type: type,
          fields: dereferenced_fields
      }
  }
end

#to_referenceObject



45
46
47
# File 'lib/universe_compiler/entity/conversion.rb', line 45

def to_reference
  UniverseCompiler::Entity::Reference.new_instance self
end

#to_uniq_idObject



16
17
18
# File 'lib/universe_compiler/entity/conversion.rb', line 16

def to_uniq_id
  Digest::SHA256.hexdigest to_composite_key.join ':'
end