Sha256: 8002652a9314e960e6e39d16ec24ca9320aa58a8c76930f0d4b54eddd054be88

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

module Pacer::Orient
  class OrientType
    extend Forwardable

    attr_reader :graph, :element_type, :type

    # TODO: setters like in Property, once I figure out what these settings do.

    def_delegators :@type,
      :name, :short_name, :type_name, :abstract?, :strict_mode?,
      :base_classes,
      :class_indexes, :indexes, :involved_indexes,
      :size, :over_size,
      :cluster_selection, :cluster_ids,
      :custom_keys, :custom

    alias class_indices class_indexes
    alias indices indexes
    alias involved_indices involved_indexes

    def initialize(graph, element_type, type)
      @graph = graph
      @element_type = type
      @type = type
    end

    def raw_property(name)
      if name.is_a? Symbol or name.is_a? String
        type.getProperty name.to_s
      else
        name
      end
    end

    def indexed?(name)
      p = property(name)
      p.indexed? if p
    end

    def property(name)
      p = raw_property(name)
      Property.new self, p if p
    end

    def property!(name, otype)
      p = raw_property(name)
      unless p
        p = graph.send(:in_pure_transaction) do
          type.createProperty(name.to_s, graph.property_type(otype))
        end
      end
      Property.new self, p
    end

    def super_class
      if base_classes.any?
        OrientType.new graph, type.getSuperClass
      end
    end

    def set_super_class(sc)
      graph.send(:in_pure_transaction) do
        type.setSuperClass graph.orient_type(element_type, sc)
      end
      self
    end

    def drop_property!(name)
      graph.send(:in_pure_transaction) do
        type.dropProperty name
      end
    end

    def properties
      type.properties.map { |p| Property.new self, p }
    end

    def indexed_properties
      type.indexedProperties.map { |p| Property.new self, p }
    end

    def inspect
      abs = "Abstract" if abstract?
      strict = " (strict)" if strict_mode?
      "#<#{ abs }#{ type_name.capitalize }Type #{ name }#{ strict }>"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pacer-orient-2.1.2-java lib/pacer-orient/orient_type.rb
pacer-orient-2.1.1-java lib/pacer-orient/orient_type.rb