Sha256: a161fa38c73505db99f6ab1b1c58afd32d08e2398291ce6f1c948d02f3be64e8

Contents?: true

Size: 652 Bytes

Versions: 11

Compression:

Stored size: 652 Bytes

Contents

module ActiveEnum
  module Storage
    class MemoryStore < AbstractStore

      def set(id, name, meta=nil)
        check_duplicate id, name
        _values << [ id, name.to_s, meta ].compact
        sort!
      end

      def get_by_id(id)
        _values.assoc(id)
      end

      def get_by_name(name)
        _values.rassoc(name.to_s) || _values.rassoc(name.to_s.titleize)
      end

      def sort!
        case @order
        when :asc
          _values.sort! { |a,b| a[0] <=> b[0] }
        when :desc
          _values.sort! { |a,b| b[0] <=> a[0] }
        end
      end

      def _values
        @_values ||= []
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
active_enum-1.2.1 lib/active_enum/storage/memory_store.rb
active_enum-1.2.0 lib/active_enum/storage/memory_store.rb
active_enum-1.1.0 lib/active_enum/storage/memory_store.rb
active_enum-1.0.0 lib/active_enum/storage/memory_store.rb
active_enum-1.0.0.rc8 lib/active_enum/storage/memory_store.rb
active_enum-1.0.0.rc7 lib/active_enum/storage/memory_store.rb
active_enum-1.0.0.rc6 lib/active_enum/storage/memory_store.rb
active_enum-1.0.0.rc5 lib/active_enum/storage/memory_store.rb
active_enum-1.0.0.rc4 lib/active_enum/storage/memory_store.rb
active_enum-1.0.0.rc3 lib/active_enum/storage/memory_store.rb
active_enum-1.0.0.rc2 lib/active_enum/storage/memory_store.rb