class ACH::Record::Dynamic

Descendants of ACH::Record::Dynamic class are the only records allowed to have previously undefined fields. However, each new field definition requires a rule string to be passed. UndefinedFormatError will be raised otherwise. If the field has already been defined, and a new rule string is passed, a DuplicateFormatError is raised.

Example

class CustomHeader < ACH::Record::Dynamic
  request_type '<-9-' => '$$ADD ID='
  remote_id    '<-8-'
  file_type    '<-6-', 'NWFACH'
end

This example declares a CustomHeader record type with following fields:

value of ‘$$ADD ID=’

Note: passing two arguments to method call is equivalent to passing a hash with a single key-value pair.

Public Class Methods

method_missing(field, *args) click to toggle source

For a dynamic record, analyze any unknown message as a pattern for new Rule, and define it for future usage on match.

@param [Symbol] field @param [*Object] args @raise [UndefinedFormatError] @raise [DuplicateFormatError]

# File lib/ach/record/dynamic.rb, line 56
def self.method_missing(field, *args)
  format, default = args.first.is_a?(Hash) ? args.first.first : args
  unless format =~ Formatter::Rule::RULE_PARSER_REGEX
    default, format = format, nil
  end
  
  unless Formatter.defined? field
    raise UndefinedFormatError.new(field) if format.nil?
    Formatter.define field, format
  else
    raise DuplicateFormatError.new(field) if format
  end
  define_field_methods(field)
  (@fields ||= []) << field
  (@defaults ||= {})[field] = default if default
end