Sha256: 3f4cabccdb0d90c929dcbb7473976677585c76a5ddcc95972b2084c6376c2df0

Contents?: true

Size: 560 Bytes

Versions: 1

Compression:

Stored size: 560 Bytes

Contents

module DataMapper
  module Support
    class Struct
      
      def self.define(raw_fields)
        
        normalized_fields = raw_fields.map { |field| Inflector.underscore(field).to_sym }
        
        Class.new(self) do
          define_method(:fields) do
            normalized_fields
          end
        end
      end
      
      def initialize(values)
        @values = values
      end

      def method_missing(sym, *args)
        @values[fields.index(sym)]
      end
      
    end # class Struct
  end # module Support
end # module DataMapper

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datamapper-0.1.1 lib/data_mapper/support/struct.rb