Sha256: bfead8065dee01da8137c3f46f798d64ab0623b3ee2deefaf0cb1e8716207ddc

Contents?: true

Size: 1.63 KB

Versions: 416

Compression:

Stored size: 1.63 KB

Contents

module AnnotatedModule

  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

  add_consummable_annotation(self,
    :description        => "",
    :inputs             => [],
    :input_types        => {},
    :input_descriptions => {},
    :input_defaults     => {},
    :input_options      => {})

  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
end

Version data entries

416 entries across 416 versions & 1 rubygems

Version Path
rbbt-util-5.21.54 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.53 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.51 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.50 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.49 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.47 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.46 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.45 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.44 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.43 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.42 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.39 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.38 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.37 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.36 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.35 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.34 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.33 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.32 lib/rbbt/workflow/annotate.rb
rbbt-util-5.21.31 lib/rbbt/workflow/annotate.rb