Sha256: 304e9d2f4f46fc6636f9a8766df7c7e358916abbc6130b3c28788d5c492e5580

Contents?: true

Size: 693 Bytes

Versions: 2

Compression:

Stored size: 693 Bytes

Contents

module MummRa
  class Repository
    include Enumerable

    def initialize(args={})
      @source     = args.fetch(:source)
      @main_class = args.fetch(:main_class)
    end

    def all
      @all ||= source.values
    end

    def each
      all.each do |value|
        yield value
      end
    end

    def [](key)
      source[key]
    end

    def construct_from_object(obj)
      return obj if obj.is_a? main_class
      return main_class.new(obj) if obj.is_a?(Hash)
      attrs = {}
      main_class.members.each do |attr|
        attrs[attr] = obj.send(attr)
      end
      main_class.new(attrs)
    end

    private
    attr_reader :source
    attr_reader :main_class

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mumm_ra-0.0.2 lib/mumm_ra/repository.rb
mumm_ra-0.0.1 lib/mumm_ra/repository.rb