Module: ActiveGraph::Base

Extended by:
Core::Schema
Includes:
Core::Querable, Transactions
Defined in:
lib/active_graph/base.rb

Overview

To contain any base login for Node/Relationship which is external to the main classes

Constant Summary

Constants included from Core::Schema

Core::Schema::FILTER

Constants included from Core::Instrumentable

Core::Instrumentable::EMPTY, Core::Instrumentable::NEWLINE_W_SPACES

Class Method Summary collapse

Methods included from Core::Schema

constraint_owned?, constraints, indexes, normalize, raw_indexes, version, version?

Class Method Details

.driverObject

private?



18
19
20
21
22
# File 'lib/active_graph/base.rb', line 18

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

.driver=(driver) ⇒ Object

Should support setting driver via config options



39
40
41
42
# File 'lib/active_graph/base.rb', line 39

def driver=(driver)
  @driver&.close
  @driver = driver
end

.establish_driverObject



28
29
30
# File 'lib/active_graph/base.rb', line 28

def establish_driver
  @establish_driver_block.call if @establish_driver_block
end

.label_object(label_name) ⇒ Object



62
63
64
# File 'lib/active_graph/base.rb', line 62

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

.loggerObject



66
67
68
# File 'lib/active_graph/base.rb', line 66

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

.magic_query(*args) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/active_graph/base.rb', line 54

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

.new_query(options = {}) ⇒ Object



49
50
51
52
# File 'lib/active_graph/base.rb', line 49

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

.on_establish_driver(&block) ⇒ Object



24
25
26
# File 'lib/active_graph/base.rb', line 24

def on_establish_driver(&block)
  @establish_driver_block = block
end

.query(*args) ⇒ Object



32
33
34
35
36
# File 'lib/active_graph/base.rb', line 32

def query(*args)
  transaction(implicit: true) do
    super(*args)
  end
end

.validating_transaction(&block) ⇒ Object



44
45
46
47
# File 'lib/active_graph/base.rb', line 44

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