Module: Lev::Routine::ClassMethods
- Defined in:
- lib/lev/routine.rb
Instance Method Summary collapse
- #[](*args, &block) ⇒ Object
- #active_job_class ⇒ Object
- #active_job_queue ⇒ Object
- #call(*args, &block) ⇒ Object
- #class_to_symbol(klass) ⇒ Object
- #delegates_to ⇒ Object
- #express_output ⇒ Object
- #nested_routines ⇒ Object
- #perform_later(*args, &block) ⇒ Object
- #raise_fatal_errors? ⇒ Boolean
- #transaction_isolation ⇒ Object
-
#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.
Instance Method Details
#[](*args, &block) ⇒ Object
203 204 205 206 207 |
# File 'lib/lev/routine.rb', line 203 def [](*args, &block) result = call(*args, &block) result.errors.raise_exception_if_any! result.outputs.send(@express_output) end |
#active_job_class ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/lev/routine.rb', line 210 def active_job_class @active_job_class ||= const_set("ActiveJob", Class.new(Lev.configuration.active_job_class) do queue_as do parent_routine.active_job_queue end def parent_routine self.class.parent end def perform(*args, &block) parent_routine.call(*args, &block) end end ) end |
#active_job_queue ⇒ Object
232 233 234 |
# File 'lib/lev/routine.rb', line 232 def active_job_queue @active_job_queue || :default end |
#call(*args, &block) ⇒ Object
199 200 201 |
# File 'lib/lev/routine.rb', line 199 def call(*args, &block) new.call(*args, &block) end |
#class_to_symbol(klass) ⇒ Object
275 276 277 |
# File 'lib/lev/routine.rb', line 275 def class_to_symbol(klass) klass.name.underscore.gsub('/','_').to_sym end |
#delegates_to ⇒ Object
262 263 264 |
# File 'lib/lev/routine.rb', line 262 def delegates_to @delegates_to end |
#express_output ⇒ Object
258 259 260 |
# File 'lib/lev/routine.rb', line 258 def express_output @express_output end |
#nested_routines ⇒ Object
266 267 268 |
# File 'lib/lev/routine.rb', line 266 def nested_routines @nested_routines ||= {} end |
#perform_later(*args, &block) ⇒ Object
228 229 230 |
# File 'lib/lev/routine.rb', line 228 def perform_later(*args, &block) active_job_class.perform_later(*args, &block) end |
#raise_fatal_errors? ⇒ Boolean
270 271 272 273 |
# File 'lib/lev/routine.rb', line 270 def raise_fatal_errors? @raise_fatal_errors || (Lev.configuration.raise_fatal_errors && @raise_fatal_errors.nil?) end |
#transaction_isolation ⇒ Object
254 255 256 |
# File 'lib/lev/routine.rb', line 254 def transaction_isolation @transaction_isolation ||= TransactionIsolation.mysql_default 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.
240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/lev/routine.rb', line 240 def uses_routine(routine_class, ={}) symbol = [:as] || class_to_symbol(routine_class) raise Lev.configuration.illegal_argument_error, "Routine #{routine_class} has already been registered" \ if nested_routines[symbol] nested_routines[symbol] = { routine_class: routine_class, options: } transaction_isolation.replace_if_more_isolated(routine_class.transaction_isolation) end |