Class: AWS::Flow::Options

Inherits:
Object
  • Object
show all
Extended by:
Utilities::UpwardLookups
Includes:
Utilities::UpwardLookups::InstanceMethods
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

Attributes included from Utilities::UpwardLookups

#precursors

Attributes included from Utilities::UpwardLookups::InstanceMethods

#precursors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities::UpwardLookups

held_properties, properties, property

Methods included from Utilities::UpwardLookups::InstanceMethods

#look_upwards

Constructor Details

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

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

Parameters:

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

    Optional. 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)

    Optional. 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.



99
100
101
102
103
104
105
106
# File 'lib/aws/decider/options.rb', line 99

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'lib/aws/decider/options.rb', line 34

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.



54
55
56
# File 'lib/aws/decider/options.rb', line 54

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).



40
41
42
43
44
45
46
47
48
# File 'lib/aws/decider/options.rb', line 40

def self.inherited(child)
  child.precursors ||= []
  default_classes = child.ancestors.map do |precursor|
    if precursor.methods.map(&:to_sym).include? :default_classes
      precursor.default_classes
    end
  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, returned as a hash.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/aws/decider/options.rb', line 72

def get_options(options, extra_to_add = {})
  options = self.class.held_properties.compact if options.empty?

  set_options = options.select do |option|
    self.send(option) != nil && self.send(option) != ""
  end

  option_values = set_options.map do |option|
    self.send(option) == Float::INFINITY ? "NONE" : self.send(option)
  end

  result = Hash[set_options.zip(option_values)]
  result.merge(extra_to_add)
end