Module: Datacaster::Transaction::ClassMethods
- Defined in:
- lib/datacaster/transaction.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, **kwargs) ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/datacaster/transaction.rb', line 54
def method_missing(m, *args, **kwargs)
return super unless args.empty? && kwargs.empty?
return super unless method_defined?(m)
method = instance_method(m)
return super unless method.arity == 1
->(*args, **kwargs) { send(m, *args, **kwargs) }
end
|
Instance Method Details
#_caster ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/datacaster/transaction.rb', line 13
def _caster
if @_block
@_caster = ContextNodes::StructureCleaner.new(@_block.(), @_strategy)
@_block = nil
@_strategy = nil
end
@_caster
end
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/datacaster/transaction.rb', line 22
def _perform(caster, strategy, &block)
if [caster, block].count(nil) != 1
raise RuntimeError, "provide either a caster as single argument, or just a block to `perform(...)` or `perform_*(...)` call", caller
end
if block
@_block = block
@_strategy = strategy
@_caster = nil
else
@_block = nil
@_strategy = nil
@_caster = ContextNodes::StructureCleaner.new(caster, strategy)
end
end
|
#call(*args, **kwargs) ⇒ Object
64
65
66
|
# File 'lib/datacaster/transaction.rb', line 64
def call(*args, **kwargs)
new.call(*args, **kwargs)
end
|
#define_steps(&block) ⇒ Object
50
51
52
|
# File 'lib/datacaster/transaction.rb', line 50
def define_steps(&block)
instance_eval(&block)
end
|
38
39
40
|
# File 'lib/datacaster/transaction.rb', line 38
def perform(caster = nil, &block)
_perform(caster, :fail, &block)
end
|
46
47
48
|
# File 'lib/datacaster/transaction.rb', line 46
def perform_choosy(caster = nil, &block)
_perform(caster, :remove, &block)
end
|
42
43
44
|
# File 'lib/datacaster/transaction.rb', line 42
def perform_partial(caster = nil, &block)
_perform(caster, :pass, &block)
end
|