Class: Barometer::Utils::VersionedRegistration

Inherits:
Object
  • Object
show all
Defined in:
lib/barometer/utils/versioned_registration.rb

Instance Method Summary collapse

Constructor Details

#initializeVersionedRegistration

Returns a new instance of VersionedRegistration.



4
5
6
# File 'lib/barometer/utils/versioned_registration.rb', line 4

def initialize
  @registrations = {}
end

Instance Method Details

#find(key, version = nil) ⇒ Object



24
25
26
27
28
# File 'lib/barometer/utils/versioned_registration.rb', line 24

def find(key, version=nil)
  return unless has_key?(key)
  registration = find_version(key, version) || find_default(key) || {}
  registration.fetch(:value, nil)
end

#register(key, *args, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/barometer/utils/versioned_registration.rb', line 8

def register(key, *args, &block)
  if block_given?
    version = args.shift
    value = block
  elsif args.size > 1
    version = args.shift
    value = args.shift
  else
    version = nil
    value = args.shift
  end

  return if has_version?(key, version)
  add_value(key, version, value)
end

#sizeObject



30
31
32
# File 'lib/barometer/utils/versioned_registration.rb', line 30

def size
  @registrations.inject(0){|count,key_value| key_value[1].size + count }
end