Module: EntityWorkflow

Defined in:
lib/scout/workflow/entity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#entity_nameObject

Returns the value of attribute entity_name.



5
6
7
# File 'lib/scout/workflow/entity.rb', line 5

def entity_name
  @entity_name
end

Class Method Details

.extended(base) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/scout/workflow/entity.rb', line 14

def self.extended(base)
  base.extend Workflow
  base.extend Entity

  base.entity_name ||= 'entity'

  base.instance_variable_set(:@annotation_inputs, IndiferentHash.setup({})) unless base.instance_variables.include?(:@annotation_inputs)
  class << base
    def annotation_input(name, type=nil, desc=nil, default=nil, options = {})
      annotation name
      annotation_inputs = self.instance_variable_get("@annotation_inputs")
      annotation_inputs[name] = [type, desc, default, options]
    end
  end

  base.helper :entity do
    base.setup(clean_name.dup, inputs.to_hash)
  end

  base.helper :entity_list do
    list = inputs.last
    list = list.load if Step === list
    base.setup(list, inputs.to_hash)
  end

  base.property job: :both  do |task_name,options={}|
    if Array === self && AnnotatedArray === self
      base.job(task_name, "Default", options.merge(list: self))
    else
      base.job(task_name, self, options)
    end
  end
end

Instance Method Details

#entity_task(task_name, *args, &block) ⇒ Object



101
102
103
# File 'lib/scout/workflow/entity.rb', line 101

def entity_task(task_name, *args, &block)
  property_task(task_name, :single, *args, &block)
end

#entity_task_alias(task_name, *args) ⇒ Object



121
122
123
# File 'lib/scout/workflow/entity.rb', line 121

def entity_task_alias(task_name, *args)
  property_task_alias(task_name, :single, *args)
end

#list_task(task_name, *args, &block) ⇒ Object



105
106
107
# File 'lib/scout/workflow/entity.rb', line 105

def list_task(task_name, *args, &block)
  property_task(task_name, :array, *args, &block)
end

#list_task_alias(task_name, *args) ⇒ Object



125
126
127
# File 'lib/scout/workflow/entity.rb', line 125

def list_task_alias(task_name, *args)
  property_task_alias(task_name, :array, *args)
end

#multiple_task(task_name, *args, &block) ⇒ Object



109
110
111
# File 'lib/scout/workflow/entity.rb', line 109

def multiple_task(task_name, *args, &block)
  property_task(task_name, :multiple, *args, &block)
end

#multiple_task_alias(task_name, *args) ⇒ Object



129
130
131
# File 'lib/scout/workflow/entity.rb', line 129

def multiple_task_alias(task_name, *args)
  property_task_alias(task_name, :multiple, *args)
end

#property_task(task_name, property_type = :single, *args, &block) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/scout/workflow/entity.rb', line 48

def property_task(task_name, property_type=:single, *args, &block)
  task_name, result_type = task_name.keys.first, task_name.values.first if Hash === task_name

  annotation_inputs = self.instance_variable_get("@annotation_inputs")
  self.annotations.each do |annotation|
    if annotation_inputs[annotation]
      input annotation, *annotation_inputs[annotation]
    else
      input annotation
    end
  end

  case property_type
  when :single, :single2array
    input entity_name, :string, "#{self.to_s} identifier", nil, jobname: true
    task(task_name => result_type, &block)
  when :both
    input entity_name, :string, "#{self.to_s} identifier", nil, jobname: true
    input :list, :array, "#{self.to_s} identifier list"
    task(task_name => result_type, &block)
  else
    input :list, :array, "#{self.to_s} identifier list"
    task(task_name => result_type, &block)
  end

  property_name = task_name.to_s.sub(/^(#{entity_name}_list|#{entity_name}|list)_/, '')
  property_job_name = property_name + '_job'

  property property_job_name => property_type do |*args|
    job(task_name, *args)
  end

  property property_name => property_type do |*args|
    job = self.send(property_job_name)

    job.join if job.running?

    if job.error?
      if job.recoverable_error?
        job.clean
      else
        raise job.exception
      end
    end

    job.run unless job.done?

    job.load
    Array === job ? job.collect(&:run) : job.run
  end

end

#property_task_alias(task_name, property_type = :single, *args) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/scout/workflow/entity.rb', line 113

def property_task_alias(task_name, property_type=:single, *args)
  task_alias task_name, *args
  property task_name => property_type do |*args|
    job = job(task_name, *args)
    Array === job ? job.collect(&:run) : job.run
  end
end