Sha256: 6338022420e6b3641e1f4de6e24ab958ceb828677d3446dd72ac764f3e5a81fc

Contents?: true

Size: 1.38 KB

Versions: 29

Compression:

Stored size: 1.38 KB

Contents

require 'digest'

module UniverseCompiler
  module Entity

    module Conversion

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

      def to_composite_key
        [type, name]
      end

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

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

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

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

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

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

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

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

    end

  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
universe_compiler-0.3.2 lib/universe_compiler/entity/conversion.rb
universe_compiler-0.3.1 lib/universe_compiler/entity/conversion.rb
universe_compiler-0.3.0 lib/universe_compiler/entity/conversion.rb
universe_compiler-0.2.16 lib/universe_compiler/entity/conversion.rb
universe_compiler-0.2.15 lib/universe_compiler/entity/conversion.rb
universe_compiler-0.2.14 lib/universe_compiler/entity/conversion.rb
universe_compiler-0.2.13 lib/universe_compiler/entity/conversion.rb
universe_compiler-0.2.12 lib/universe_compiler/entity/conversion.rb
universe_compiler-0.2.11 lib/universe_compiler/entity/conversion.rb