Sha256: 2b932afbb53f8ed5daf66c7ca04abea41a03d5adfc17ee2a1e825844f7c290b6

Contents?: true

Size: 863 Bytes

Versions: 36

Compression:

Stored size: 863 Bytes

Contents

module Lolita
  
  class Register
    def initialize
      @store = {}
    end

    def set key, value, options=nil
      !!(@store[key] = [value,options].compact)
    end

    def get key
      item = @store[key] and item.first
    end

    def get_with_options key
      @store[key]
    end

    def filter *args
      options = args.extract_options!
      values = if args.first
        [get_with_options(args.first)]
      else
        @store.values
      end
      filter_values(values,options)
    end

    private

    def filter_values values, pattern
      unless (pattern && pattern.any?)
        values
      else
        values.inject([]) do |result,value|
          if value[1]
            if (pattern.to_a - value[1].to_a).empty?
              result.push value
            end
          end
          result
        end
      end
    end
  end

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
lolita-4.0.11 lib/lolita/register.rb
lolita-4.2.0 lib/lolita/register.rb
lolita-4.0.10 lib/lolita/register.rb
lolita-4.0.9 lib/lolita/register.rb
lolita-4.0.8 lib/lolita/register.rb
lolita-4.0.7 lib/lolita/register.rb
lolita-4.0.6 lib/lolita/register.rb
lolita-4.0.5 lib/lolita/register.rb
lolita-4.0.4 lib/lolita/register.rb
lolita-4.0.3 lib/lolita/register.rb
lolita-4.0.2 lib/lolita/register.rb
lolita-4.0.1 lib/lolita/register.rb
lolita-4.0.0 lib/lolita/register.rb
lolita-3.4.3 lib/lolita/register.rb
lolita-3.4.2 lib/lolita/register.rb
lolita-3.4.1 lib/lolita/register.rb
lolita-3.4.0 lib/lolita/register.rb
lolita-3.3.9 lib/lolita/register.rb
lolita-3.3.8 lib/lolita/register.rb
lolita-3.3.7 lib/lolita/register.rb