Module: AnnotatedModule

Included in:
Workflow
Defined in:
lib/rbbt/workflow/annotate.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_consummable_annotation(target, *annotations) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rbbt/workflow/annotate.rb', line 3

def self.add_consummable_annotation(target, *annotations)
  if annotations.length == 1 and Hash === annotations.first
    annotations.first.each do |annotation, default|
      target.send(:attr_accessor, annotation)
      target.send(:define_method, "consume_#{annotation}") do
        value = instance_variable_get("@#{annotation}") || default.dup
        instance_variable_set("@#{annotation}", default.dup)
        value
      end
    end
  else
    annotations.each do |annotation|
      target.send(:attr_accessor, annotation)
      target.send(:define_method, "consume_#{annotation}") do
        value = instance_variable_get("@#{annotation}")
        instance_variable_set("@#{annotation}", nil)
      end
    end
  end
end

Instance Method Details

#input(name, type = nil, desc = nil, default = nil, options = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rbbt/workflow/annotate.rb', line 32

def input(name, type = nil, desc = nil, default = nil, options = nil)
  name = name.to_sym
  type = type.to_sym

  @inputs             = [] if @inputs.nil?
  @input_types        = {} if @input_types.nil?
  @input_descriptions = {} if @input_descriptions.nil?
  @input_defaults     = {} if @input_defaults.nil?
  @input_options      = {} if @input_options.nil?

  @inputs                   << name
  @input_types[name]        = type unless type.nil?
  @input_descriptions[name] = desc unless desc.nil?
  @input_defaults[name]     = default unless default.nil?
  @input_options[name]      = options unless options.nil?
end