Class: Clomp::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/clomp/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options: {}, tracks: [], operation: nil) ⇒ Result

Returns a new instance of Result.



5
6
7
8
9
10
11
12
13
# File 'lib/clomp/result.rb', line 5

def initialize(options: {}, tracks: [], operation: nil)
  @report = {}
  
  @operation      = set_prop :operation, operation || Operation.new
  @tracks         = set_prop :tracks, tracks || []
  @options        ||= {}
  @immutable_data = set_prop :options, options
  @state          = ->(tracks) { tracks.select {|track| track.failure?}.count.zero? }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/clomp/result.rb', line 23

def method_missing(method, *args)
  if @operation.respond_to?(method)
    @operation.send(method, *args)
  else
    super
  end
end

Instance Attribute Details

#operationObject (readonly)

Returns the value of attribute operation.



3
4
5
# File 'lib/clomp/result.rb', line 3

def operation
  @operation
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/clomp/result.rb', line 3

def options
  @options
end

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/clomp/result.rb', line 3

def state
  @state
end

Instance Method Details

#[](key) ⇒ Object



31
32
33
34
35
# File 'lib/clomp/result.rb', line 31

def [](key)
  sym_key = to_sym_key(key)
  
  self.instance_variable_get(sym_key)
end

#[]=(key, value) ⇒ Object



37
38
39
40
# File 'lib/clomp/result.rb', line 37

def []=(key, value)
  sym_key = to_sym_key(key)
  self.instance_variable_set(sym_key, value)
end

#failure?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/clomp/result.rb', line 19

def failure?
  @state.(self[:tracks]) === false
end

#set_prop(key, value) ⇒ Object



42
43
44
45
46
# File 'lib/clomp/result.rb', line 42

def set_prop(key, value)
  sym_key = to_sym_key(key)
  
  self.instance_variable_set(sym_key, value)
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/clomp/result.rb', line 15

def success?
  @state.(self[:tracks]) === true
end