Module: Neo4j::ActiveBase
- Defined in:
- lib/neo4j/active_base.rb,
lib/neo4j/active_base/session_registry.rb
Overview
To contain any base login for ActiveNode/ActiveRel which is external to the main classes
Defined Under Namespace
Classes: SessionRegistry
Class Method Summary collapse
- .current_adaptor=(adaptor) ⇒ Object
-
.current_session ⇒ Object
private?.
-
.current_session=(session) ⇒ Object
Should support setting session via config options.
- .current_transaction ⇒ Object
- .current_transaction_or_session ⇒ Object
- .establish_session ⇒ Object
- .label_object(label_name) ⇒ Object
- .logger ⇒ Object
- .magic_query(*args) ⇒ Object
- .new_query(options = {}) ⇒ Object
- .new_transaction ⇒ Object
- .on_establish_session(&block) ⇒ Object
- .query(*args) ⇒ Object
- .run_transaction(run_in_tx = true) ⇒ Object
Class Method Details
.current_adaptor=(adaptor) ⇒ Object
34 35 36 |
# File 'lib/neo4j/active_base.rb', line 34 def current_adaptor=(adaptor) self.current_session = Neo4j::Core::CypherSession.new(adaptor) end |
.current_session ⇒ Object
private?
7 8 9 10 11 |
# File 'lib/neo4j/active_base.rb', line 7 def current_session (SessionRegistry.current_session ||= establish_session).tap do |session| fail 'No session defined!' if session.nil? end end |
.current_session=(session) ⇒ Object
Should support setting session via config options
30 31 32 |
# File 'lib/neo4j/active_base.rb', line 30 def current_session=(session) SessionRegistry.current_session = make_session_wrap!(session) end |
.current_transaction ⇒ Object
62 63 64 65 |
# File 'lib/neo4j/active_base.rb', line 62 def current_transaction validate_model_schema! Neo4j::Transaction.current_for(current_session) end |
.current_transaction_or_session ⇒ Object
21 22 23 |
# File 'lib/neo4j/active_base.rb', line 21 def current_transaction_or_session current_transaction || current_session end |
.establish_session ⇒ Object
17 18 19 |
# File 'lib/neo4j/active_base.rb', line 17 def establish_session make_session_wrap!(@establish_session_block.call) if @establish_session_block end |
.label_object(label_name) ⇒ Object
67 68 69 |
# File 'lib/neo4j/active_base.rb', line 67 def label_object(label_name) Neo4j::Core::Label.new(label_name, current_session) end |
.logger ⇒ Object
71 72 73 |
# File 'lib/neo4j/active_base.rb', line 71 def logger @logger ||= (Neo4j::Config[:logger] || ActiveSupport::Logger.new(STDOUT)) end |
.magic_query(*args) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/neo4j/active_base.rb', line 54 def magic_query(*args) if args.empty? || args.map(&:class) == [Hash] ActiveBase.new_query(*args) else ActiveBase.current_session.query(*args) end end |
.new_query(options = {}) ⇒ Object
49 50 51 52 |
# File 'lib/neo4j/active_base.rb', line 49 def new_query( = {}) validate_model_schema! Neo4j::Core::Query.new({session: current_session}.merge()) end |
.new_transaction ⇒ Object
44 45 46 47 |
# File 'lib/neo4j/active_base.rb', line 44 def new_transaction validate_model_schema! Neo4j::Transaction.new(current_session) end |
.on_establish_session(&block) ⇒ Object
13 14 15 |
# File 'lib/neo4j/active_base.rb', line 13 def on_establish_session(&block) @establish_session_block = block end |
.query(*args) ⇒ Object
25 26 27 |
# File 'lib/neo4j/active_base.rb', line 25 def query(*args) current_transaction_or_session.query(*args) end |
.run_transaction(run_in_tx = true) ⇒ Object
38 39 40 41 42 |
# File 'lib/neo4j/active_base.rb', line 38 def run_transaction(run_in_tx = true) Neo4j::Transaction.run(current_session, run_in_tx) do |tx| yield tx end end |