Class: Wicked::Pipeline::BasePipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/wicked/pipeline/base_pipeline.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.blocked?(resource) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/wicked/pipeline/base_pipeline.rb', line 83

def blocked?(resource)
  new.blocked?(resource)
end

.find_step(step) ⇒ Object



95
96
97
# File 'lib/wicked/pipeline/base_pipeline.rb', line 95

def find_step(step)
  new.find_step(step)
end

.first_step?(step) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/wicked/pipeline/base_pipeline.rb', line 87

def first_step?(step)
  new.first_step?(step)
end

.last_step?(step) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/wicked/pipeline/base_pipeline.rb', line 91

def last_step?(step)
  new.last_step?(step)
end

.metadata(resource) ⇒ Object



115
116
117
# File 'lib/wicked/pipeline/base_pipeline.rb', line 115

def (resource)
  new.(resource)
end

.next_step(current_step) ⇒ Object



99
100
101
# File 'lib/wicked/pipeline/base_pipeline.rb', line 99

def next_step(current_step)
  new.next_step(current_step)
end

.next_step?(current_step, step) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/wicked/pipeline/base_pipeline.rb', line 107

def next_step?(current_step, step)
  new.next_step(current_step, step)
end

.previous_step(current_step) ⇒ Object



103
104
105
# File 'lib/wicked/pipeline/base_pipeline.rb', line 103

def previous_step(current_step)
  new.previous_step(current_step)
end

.previous_step?(current_step, step) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/wicked/pipeline/base_pipeline.rb', line 111

def previous_step?(current_step, step)
  new.previous_step(current_step, step)
end

.stepsObject



75
76
77
# File 'lib/wicked/pipeline/base_pipeline.rb', line 75

def steps
  new.steps
end

.to_aryObject Also known as: to_a



119
120
121
# File 'lib/wicked/pipeline/base_pipeline.rb', line 119

def to_ary
  new.to_ary
end

.valid?(resource) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/wicked/pipeline/base_pipeline.rb', line 79

def valid?(resource)
  new.valid?(resource)
end

Instance Method Details

#blocked?(resource) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/wicked/pipeline/base_pipeline.rb', line 14

def blocked?(resource)
  steps.any? { |step| step.new(resource).blocking? }
end

#find_step(the_step) ⇒ Object



26
27
28
# File 'lib/wicked/pipeline/base_pipeline.rb', line 26

def find_step(the_step)
  steps.find { |step| step == the_step || step.step_name == the_step }
end

#first_step?(step) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/wicked/pipeline/base_pipeline.rb', line 18

def first_step?(step)
  steps.first == step
end

#last_step?(step) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/wicked/pipeline/base_pipeline.rb', line 22

def last_step?(step)
  steps.last == step
end

#metadata(resource) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/wicked/pipeline/base_pipeline.rb', line 52

def (resource)
  steps.each_with_index.with_object(ActiveSupport::HashWithIndifferentAccess.new) do |(step, idx), obj|
    processor = step.new(resource)
     = obj.fetch(obj.keys[idx - 1], {})

    obj[processor.step_name] = {
      valid: processor.valid?,
      blocking: processor.blocking?,
      accessible: idx == 0 || (
        ![:blocking] &&
        [:accessible] &&
        [:valid]
      )
    }
  end
end

#next_step(current_step) ⇒ Object



30
31
32
33
34
# File 'lib/wicked/pipeline/base_pipeline.rb', line 30

def next_step(current_step)
  step, step_index = steps.each_with_index.find { |step, _| step == current_step || step.step_name == current_step }

  last_step?(step) || step_index.nil? ? nil : steps[step_index + 1]
end

#next_step?(current_step, step) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/wicked/pipeline/base_pipeline.rb', line 42

def next_step?(current_step, step)
  !current_step.nil? && !step.nil? &&
    next_step(current_step) == step
end

#previous_step(current_step) ⇒ Object



36
37
38
39
40
# File 'lib/wicked/pipeline/base_pipeline.rb', line 36

def previous_step(current_step)
  step, step_index = steps.each_with_index.find { |step, _| step == current_step || step.step_name == current_step }

  first_step?(step) || step_index.nil? ? nil : steps[step_index - 1]
end

#previous_step?(current_step, step) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/wicked/pipeline/base_pipeline.rb', line 47

def previous_step?(current_step, step)
  !current_step.nil? && !step.nil? &&
    previous_step(current_step) == step
end

#stepsObject



6
7
8
# File 'lib/wicked/pipeline/base_pipeline.rb', line 6

def steps
  []
end

#to_aObject



72
73
74
# File 'lib/wicked/pipeline/base_pipeline.rb', line 72

def to_ary
  steps
end

#to_aryObject



69
70
71
# File 'lib/wicked/pipeline/base_pipeline.rb', line 69

def to_ary
  steps
end

#valid?(resource) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/wicked/pipeline/base_pipeline.rb', line 10

def valid?(resource)
  steps.all? { |step| step.new(resource).valid? }
end