Sha256: daddaf3b8cc386f1eb24be19682ce39ada7cb073ec2c73e3181f1c6fb53ed44f

Contents?: true

Size: 1.73 KB

Versions: 14

Compression:

Stored size: 1.73 KB

Contents

require 'active_graph/core/querable'
require 'active_graph/core/schema'

module ActiveGraph
  # To contain any base login for Node/Relationship which
  # is external to the main classes
  module Base
    include ActiveGraph::Transactions
    include ActiveGraph::Core::Querable
    extend ActiveGraph::Core::Schema

    at_exit do
      @driver&.close
    end

    class << self
      # private?
      def driver
        (@driver ||= establish_driver).tap do |driver|
          fail 'No driver defined!' if driver.nil?
        end
      end

      def on_establish_driver(&block)
        @establish_driver_block = block
      end

      def establish_driver
        @establish_driver_block.call if @establish_driver_block
      end

      def query(*args)
        transaction do
          super(*args)
        end
      end

      # Should support setting driver via config options
      def driver=(driver)
        @driver&.close
        @driver = driver
      end

      def validating_transaction(&block)
        validate_model_schema!
        transaction(&block)
      end

      def new_query(options = {})
        validate_model_schema!
        ActiveGraph::Core::Query.new(options)
      end

      def magic_query(*args)
        if args.empty? || args.map(&:class) == [Hash]
          new_query(*args)
        else
          query(*args)
        end
      end

      def label_object(label_name)
        ActiveGraph::Core::Label.new(label_name)
      end

      def logger
        @logger ||= (ActiveGraph::Config[:logger] || ActiveSupport::Logger.new(STDOUT))
      end

      private

      def validate_model_schema!
        ActiveGraph::ModelSchema.validate_model_schema! unless ActiveGraph::Migrations.currently_running_migrations
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
activegraph-10.2.0.beta.1 lib/active_graph/base.rb
activegraph-10.1.1 lib/active_graph/base.rb
activegraph-10.1.0 lib/active_graph/base.rb
activegraph-10.0.2 lib/active_graph/base.rb
activegraph-10.0.1 lib/active_graph/base.rb
activegraph-10.0.0 lib/active_graph/base.rb
activegraph-10.0.0.pre.beta.11 lib/active_graph/base.rb
activegraph-10.0.0.pre.beta.10 lib/active_graph/base.rb
activegraph-10.0.0.pre.beta.9 lib/active_graph/base.rb
activegraph-10.0.0.pre.beta.8 lib/active_graph/base.rb
activegraph-10.0.0.pre.beta.7 lib/active_graph/base.rb
activegraph-10.0.0.pre.beta.6 lib/active_graph/base.rb
activegraph-10.0.0.pre.beta.5 lib/active_graph/base.rb
activegraph-10.0.0.pre.beta.4 lib/active_graph/base.rb