Sha256: 78b1e7960e8ece0ba53aad7376c01cc0a86567368ebdaf96948b63eeec32a56d

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 KB

Contents

module ATP
  module FlowAPI
    def atp=(atp)
      @atp = atp
    end

    def atp
      @atp
    end

    ([:test, :bin, :pass, :continue, :cz, :log, :sub_test, :volatile, :set_flag, :enable, :disable, :render,
      :context_changed?, :ids, :describe_bin, :describe_softbin, :describe_soft_bin] +
      ATP::Flow::CONDITION_KEYS.keys).each do |method|
      define_method method do |*args, &block|
        options = args.pop if args.last.is_a?(Hash)
        options ||= {}
        add_meta!(options) if respond_to?(:add_meta!, true)
        add_description!(options) if respond_to?(:add_description!, true)
        args << options
        atp.send(method, *args, &block)
      end
    end

    alias_method :logprint, :log

    def lo_limit(value, options)
      {
        value:    value,
        rule:     options[:rule] || :gte,
        units:    options[:units],
        selector: options[:selector] || options[:test_mode]
      }
    end

    def hi_limit(value, options)
      {
        value:    value,
        rule:     options[:rule] || :lte,
        units:    options[:units],
        selector: options[:selector] || options[:test_mode]
      }
    end

    def limit(value, options)
      unless options[:rule]
        fail 'You must supply option :rule (e.g. rule: :gt) when calling the limit helper'
      end
      {
        value:    value,
        rule:     options[:rule] || :lt,
        units:    options[:units],
        selector: options[:selector] || options[:test_mode]
      }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
atp-1.1.3 lib/atp/flow_api.rb
atp-1.1.2 lib/atp/flow_api.rb
atp-1.1.1 lib/atp/flow_api.rb
atp-1.1.0 lib/atp/flow_api.rb