Class: Pakyow::Operation

Inherits:
Object
  • Object
show all
Extended by:
Support::ClassState, Support::Makeable
Includes:
Behavior::Verification, Support::Pipeline, Support::Pipeline::Object
Defined in:
lib/pakyow/operation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Behavior::Verification

#verify

Constructor Details

#initialize(app:, **values) ⇒ Operation

Returns a new instance of Operation.


25
26
27
# File 'lib/pakyow/operation.rb', line 25

def initialize(app:, **values)
  @app, @values = app, values
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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


39
40
41
42
43
44
45
46
# File 'lib/pakyow/operation.rb', line 39

def method_missing(name, *args, &block)
  name = name.to_sym
  if @values.key?(name)
    @values[name.to_sym]
  else
    super
  end
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.


20
21
22
# File 'lib/pakyow/operation.rb', line 20

def app
  @app
end

#valuesObject (readonly)

Returns the value of attribute values.


20
21
22
# File 'lib/pakyow/operation.rb', line 20

def values
  @values
end

Class Method Details

.handle(error = nil, &block) ⇒ Object


65
66
67
# File 'lib/pakyow/operation.rb', line 65

def handle(error = nil, &block)
  @__handlers[error || :global] = block
end

.verify(&block) ⇒ Object

Perform input verification before performing the operation

See Also:


57
58
59
60
61
62
63
# File 'lib/pakyow/operation.rb', line 57

def verify(&block)
  define_method :__verify do
    verify(&block)
  end

  action :__verify
end

Instance Method Details

#performObject


29
30
31
32
33
34
35
36
37
# File 'lib/pakyow/operation.rb', line 29

def perform
  call(self)
rescue => error
  if handler = self.class.__handlers[error.class] || self.class.__handlers[:global]
    instance_exec(&handler); self
  else
    raise error
  end
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/pakyow/operation.rb', line 48

def respond_to_missing?(name, include_private = false)
  @values.key?(name.to_sym) || super
end