Module: Diametric::Persistence::Peer::ClassMethods

Defined in:
lib/diametric/persistence/peer.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object


222
223
224
225
226
227
228
229
230
231
232
# File 'lib/diametric/persistence/peer.rb', line 222

def method_missing(method_name, *args, &block)
  db_functions = self.instance_variable_get("@db_functions")
  if db_functions && db_functions.include?(method_name)
    params = args.dup
    conn = params.shift
    function = conn.db.entity(method_name)
    function.exec(*params)
  else
    super
  end
end

Instance Method Details

#all(connection = nil, resolve = true) ⇒ Object


173
174
175
176
# File 'lib/diametric/persistence/peer.rb', line 173

def all(connection=nil, resolve=true)
  connection ||= Diametric::Persistence::Peer.connect
  Diametric::Query.new(self, connection, resolve).all
end

#create_schema(connection = nil) ⇒ Object


168
169
170
171
# File 'lib/diametric/persistence/peer.rb', line 168

def create_schema(connection=nil)
  connection ||= Diametric::Persistence::Peer.connect
  connection.transact(schema)
end

#db_functionsObject


213
214
215
216
217
218
219
220
# File 'lib/diametric/persistence/peer.rb', line 213

def db_functions
  db_functions = self.instance_variable_get("@db_functions")
  unless db_functions
    db_functions = ::Set.new
    self.instance_variable_set("@db_functions", db_functions)
  end
  db_functions
end

#filter(connection, *filter) ⇒ Object


189
190
191
192
193
# File 'lib/diametric/persistence/peer.rb', line 189

def filter(connection, *filter)
  connection ||= Diametric::Persistence::Peer.connect
  query = Diametric::Query.new(self, connection, true)
  query.filter(*filter)
end

#first(conditions = {}, connection = nil, resolve = true) ⇒ Object


178
179
180
181
# File 'lib/diametric/persistence/peer.rb', line 178

def first(conditions = {}, connection=nil, resolve=true)
  connection ||= Diametric::Persistence::Peer.connect
  where(conditions, connection, resolve).first
end

#get(dbid, connection = nil, resolve = false) ⇒ Object


195
196
197
198
199
200
201
# File 'lib/diametric/persistence/peer.rb', line 195

def get(dbid, connection=nil, resolve=false)
  entity = self.new
  dbid = dbid.to_i if dbid.is_a?(String)
  connection ||= Diametric::Persistence::Peer.connect
  entity = self.reify(dbid, connection, resolve)
  entity
end

#q(query, args, conn_or_db = nil) ⇒ Object


203
204
205
206
207
208
209
210
211
# File 'lib/diametric/persistence/peer.rb', line 203

def q(query, args, conn_or_db=nil)
  conn_or_db ||= Diametric::Persistence::Peer.connect
  if conn_or_db.is_a?(Diametric::Persistence::Connection)
    db = conn_or_db.db
  else
    db = conn_or_db
  end
  Diametric::Persistence::Peer.q(query, db, args.flatten(1))
end

#tempid(*e) ⇒ Diametric::Persistence::Object

Create a temporary id placeholder.

Parameters:

  • e (*#to_edn)

    Elements to put in the placeholder. Should be either partition or partition and a negative number to be used as a reference.

Returns:

  • (Diametric::Persistence::Object)

    Temporary id placeholder.


159
160
161
162
163
164
165
166
# File 'lib/diametric/persistence/peer.rb', line 159

def tempid(*e)
  if e.size == 1
    return Diametric::Persistence::Peer.tempid(e[0])
  elsif e.size == 2
    return Diametric::Persistence::Peer.tempid(e[0], e[1])
  end
  nil
end

#where(conditions = {}, connection = nil, resolve = true) ⇒ Object


183
184
185
186
187
# File 'lib/diametric/persistence/peer.rb', line 183

def where(conditions = {}, connection=nil, resolve=true)
  connection ||= Diametric::Persistence::Peer.connect
  query = Diametric::Query.new(self, connection, resolve)
  query.where(conditions)
end