module Stockboy::MappedRecord::AccessorMethods

This is an optimization to avoid relying on method_missing.

This module holds a pool of already-defined accessor methods for sets of record attributes. Each set of methods is held in a module that gets extended into new MappedRecords.

@visibility private

Public Class Methods

build_module(attr_accessor_keys) click to toggle source
# File lib/stockboy/mapped_record.rb, line 29
def self.build_module(attr_accessor_keys)
  Module.new do
    attr_accessor_keys.each do |key|
      define_method key do
        @fields[key]
      end
    end
  end
end
for(attrs) click to toggle source
# File lib/stockboy/mapped_record.rb, line 24
def self.for(attrs)
  @module_registry        ||= Hash.new
  @module_registry[attrs] ||= build_module(attrs)
end