Module: Lev::Routine::ClassMethods

Defined in:
lib/lev/routine.rb

Instance Method Summary collapse

Instance Method Details

#call(*args, &block) ⇒ Object



194
195
196
# File 'lib/lev/routine.rb', line 194

def call(*args, &block)
  new.call(*args, &block)
end

#class_to_symbol(klass) ⇒ Object



227
228
229
# File 'lib/lev/routine.rb', line 227

def class_to_symbol(klass)
  klass.name.underscore.gsub('/','_').to_sym
end

#default_transaction_isolationObject



219
220
221
# File 'lib/lev/routine.rb', line 219

def default_transaction_isolation
  TransactionIsolation.mysql_default
end

#nested_routinesObject



223
224
225
# File 'lib/lev/routine.rb', line 223

def nested_routines
  @nested_routines ||= {}
end

#transaction_isolationObject



215
216
217
# File 'lib/lev/routine.rb', line 215

def transaction_isolation
  @transaction_isolation ||= default_transaction_isolation
end

#uses_routine(routine_class, options = {}) ⇒ Object

Called at a routine’s class level to foretell which other routines will be used when this routine executes. Helpful for figuring out ahead of time what kind of transaction isolation level should be used.

Raises:

  • (IllegalArgument)


201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/lev/routine.rb', line 201

def uses_routine(routine_class, options={})
  symbol = options[:as] || class_to_symbol(routine_class)

  raise IllegalArgument, "Routine #{routine_class} has already been registered" \
    if nested_routines[symbol]

  nested_routines[symbol] = {
    routine_class: routine_class,
    options: options
  }

  transaction_isolation.replace_if_more_isolated(routine_class.transaction_isolation)
end