Class: ActiveGraph::Node::OrmAdapter

Inherits:
OrmAdapter::Base
  • Object
show all
Defined in:
lib/active_graph/node/orm_adapter.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#column_namesObject



8
9
10
# File 'lib/active_graph/node/orm_adapter.rb', line 8

def column_names
  klass._decl_props.keys
end

#create!(attributes = {}) ⇒ Object

Create a model using attributes



53
54
55
# File 'lib/active_graph/node/orm_adapter.rb', line 53

def create!(attributes = {})
  klass.create!(attributes)
end

#destroy(object) ⇒ Object

See Also:

  • OrmAdapter::Base#destroy


58
59
60
# File 'lib/active_graph/node/orm_adapter.rb', line 58

def destroy(object)
  object.destroy && true if valid_object?(object)
end

#find_all(options = {}) ⇒ Object

Find all models matching conditions



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/active_graph/node/orm_adapter.rb', line 40

def find_all(options = {})
  conditions, order, limit, offset = extract_conditions!(options)
  extract_id!(conditions)
  order = hasherize_order(order)

  result = klass.where(conditions)
  result = result.order(order) unless order.empty?
  result = result.skip(offset) if offset
  result = result.limit(limit) if limit
  result.to_a
end

#find_first(options = {}) ⇒ Object

Find the first instance matching conditions



29
30
31
32
33
34
35
36
37
# File 'lib/active_graph/node/orm_adapter.rb', line 29

def find_first(options = {})
  conditions, order = extract_conditions!(options)
  extract_id!(conditions)
  order = hasherize_order(order)

  result = klass.where(conditions)
  result = result.order(order) unless order.empty?
  result.first
end

#get(id) ⇒ Object

Get an instance by id of the model



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

def get(id)
  klass.find_by(klass.id_property_name => wrap_key(id))
end

#get!(id) ⇒ Object

Get an instance by id of the model



17
18
19
20
21
# File 'lib/active_graph/node/orm_adapter.rb', line 17

def get!(id)
  klass.find(wrap_key(id)).tap do |node|
    fail 'No record found' if node.nil?
  end
end

#i18n_scopeObject



12
13
14
# File 'lib/active_graph/node/orm_adapter.rb', line 12

def i18n_scope
  :neo4j
end