Class: AWS::Flow::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/decider/options.rb

Overview

The base class for all options classes in the AWS Flow Framework for Ruby.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}, use_defaults = false) ⇒ Options

Creates a new AWS::Flow::Options instance.

Parameters:

  • hash (Hash) (defaults to: {})

    A hash of values to use as the default options for this instance. The members of this hash are defined by classes derived from AWS::Flow::Options.

  • use_defaults (true, false) (defaults to: false)

    In derived classes, this parameter is used to tell the constructor to use the set of default options as the runtime options. This has no effect in the base AWS::Flow::Options class.



79
80
81
82
83
84
85
86
# File 'lib/aws/decider/options.rb', line 79

def initialize(hash={}, use_defaults = false)
  @precursors ||= []
  hash.each_pair do |key, val|
    if self.methods.map(&:to_sym).include? "#{key}=".to_sym
      self.send("#{key}=", val)
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



30
31
32
# File 'lib/aws/decider/options.rb', line 30

def method_missing(method_name, *args, &block)
  return nil
end

Class Attribute Details

.default_classesObject

The set of default options. These are used when ‘use_defaults` is set to `true` on #initialize.



45
46
47
# File 'lib/aws/decider/options.rb', line 45

def default_classes
  @default_classes
end

Class Method Details

.inherited(child) ⇒ Object

Sets the default classes on a child class (a class derived from AWS::Flow::Options).



35
36
37
38
39
40
41
# File 'lib/aws/decider/options.rb', line 35

def self.inherited(child)
  child.precursors ||= []
  default_classes = child.ancestors.map do |precursor|
    precursor.default_classes if precursor.methods.map(&:to_sym).include? :default_classes
  end.compact.flatten
  child.instance_variable_set("@default_classes", default_classes)
end

Instance Method Details

#get_options(options, extra_to_add = {}) ⇒ Hash

Merges specified options with the set of options already held by the class, and returns the result.

Parameters:

  • options (Options)

    An AWS::Flow::Options-derived class containing a set of options to use if this instance has no options, or options to add to this one if this instance already has options.

  • extra_to_add (Hash) (defaults to: {})

    A hash containing extra options to merge with the options held by the class and those provided in the options parameter.

Returns:

  • (Hash)

    The merged set of options, defined as a hash.



61
62
63
64
65
66
67
# File 'lib/aws/decider/options.rb', line 61

def get_options(options, extra_to_add = {})
  options = self.class.held_properties.compact if options.empty?
  set_options = options.select {|option| self.send(option) != nil && self.send(option) != "" }
  option_values = set_options.map {|option| self.send(option) == Float::INFINITY ? "NONE" : self.send(option) }
  result = Hash[set_options.zip(option_values)]
  result.merge(extra_to_add)
end