Module: Catena::Lang

Includes:
Funkify
Included in:
Scheduler, Task
Defined in:
lib/catena/lang.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.callback_to_func_name(callback_name) ⇒ Object

Helper functions



28
29
30
31
# File 'lib/catena/lang.rb', line 28

def self.callback_to_func_name(callback_name)
  # strip the "__"
  callback_name[2..-1]
end

.func_name_to_callback(func_name) ⇒ Object



33
34
35
# File 'lib/catena/lang.rb', line 33

def self.func_name_to_callback(func_name)
  "__#{func_name}"
end

.included(base_mod) ⇒ Object

we add the class methods to the base class so they don’t have to.



8
9
10
# File 'lib/catena/lang.rb', line 8

def self.included(base_mod)
  base_mod.extend ClassMethods
end

Instance Method Details

#bind(*args) ⇒ Object

bind(callback_name, arg1, arg2, …)



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/catena/lang.rb', line 54

def bind(*args)
  raise "Need at least callback_name" if args.length < 1
  func_name = args[0]
  func_args = args[1..-1] || []
  {
    "type" => "binding",
    "callback_name" => Lang.func_name_to_callback(func_name),
    "callback_args" => func_args,
    "cancel" => nil,
  }
end

#failure(error) ⇒ Object



46
47
48
49
50
51
# File 'lib/catena/lang.rb', line 46

def failure(error)
  {
    "type" => "failure",
    "error" => error
  }
end

#succeed(value) ⇒ Object

basic tasks and their composition that return task nodes



39
40
41
42
43
44
# File 'lib/catena/lang.rb', line 39

def succeed(value)
  {
    "type" => "succeed",
    "value" => value
  }
end