Sha256: 8dd75e098174737172698ce5d9254103592f799130f4914a07e402f1ea74a055

Contents?: true

Size: 1.81 KB

Versions: 20

Compression:

Stored size: 1.81 KB

Contents

module Foobara
  module Manifest
    # TODO: override new to return Entity when it's an entity
    class Type < BaseManifest
      self.category_symbol = :type

      class << self
        def new(root_manifest, path)
          type = super

          if self == Type
            if type.entity?
              type = Entity.new(type.root_manifest, type.path)
            elsif type.model?
              type = Model.new(type.root_manifest, type.path)
            end
          end

          type
        end
      end

      def type_manifest
        relevant_manifest
      end

      def entity?
        type = base_type

        while type
          return true if type.reference.to_sym == :entity

          type = type.base_type
        end

        false
      end

      def model?
        return false if reference == "entity"

        type = base_type

        while type
          return true if type.reference.to_sym == :model

          type = type.base_type
        end

        false
      end

      def base_type
        base_type_symbol = self[:base_type]

        if base_type_symbol
          Type.new(root_manifest, [:type, self[:base_type]])
        end
      end

      def target_class
        if target_classes.size != 1
          # :nocov:
          raise "Can only use #target_class for types with one target class but #{name} has #{target_classes.size}"
          # :nocov:
        end

        target_classes.first
      end

      def types_depended_on
        @types_depended_on ||= self[:types_depended_on].map do |type_reference|
          Type.new(root_manifest, [:type, type_reference])
        end
      end

      def type_name
        scoped_name
      end

      def full_type_name
        scoped_full_name
      end

      def builtin?
        BuiltinTypes.builtin_reference?(reference)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.25 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.24 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.23 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.22 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.21 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.20 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.19 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.18 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.17 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.16 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.15 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.14 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.13 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.12 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.11 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.10 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.9 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.8 projects/manifest/src/foobara/manifest/type.rb
foobara-0.0.7 projects/manifest/src/foobara/manifest/type.rb