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



14
15
16
# File 'lib/active_graph/node/orm_adapter.rb', line 14

def column_names
  klass._decl_props.keys
end

#create!(attributes = {}) ⇒ Object

Create a model using attributes



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

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

#destroy(object) ⇒ Object

See Also:

  • OrmAdapter::Base#destroy


64
65
66
# File 'lib/active_graph/node/orm_adapter.rb', line 64

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

#find_all(options = {}) ⇒ Object

Find all models matching conditions



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_graph/node/orm_adapter.rb', line 46

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



35
36
37
38
39
40
41
42
43
# File 'lib/active_graph/node/orm_adapter.rb', line 35

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



30
31
32
# File 'lib/active_graph/node/orm_adapter.rb', line 30

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



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

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

#i18n_scopeObject



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

def i18n_scope
  :neo4j
end