module Mustermann::Versions

Mixin that adds support for multiple versions of the same type. @see Mustermann::Rails @!visibility private

Public Instance Methods

[](version) click to toggle source

Resolve a subclass for a given version string. @!visibility private

# File lib/mustermann/versions.rb, line 30
def [](version)
  return versions.values.last unless version
  detected = versions.detect { |v,_| version.start_with?(v) }
  raise ArgumentError, 'unsupported version %p' % version unless detected
  detected.last
end
inspect() click to toggle source

@!visibility private

# File lib/mustermann/versions.rb, line 43
def inspect
  name
end
name() click to toggle source

@!visibility private

Calls superclass method
# File lib/mustermann/versions.rb, line 38
def name
  super || superclass.name
end
new(*args, version: nil, **options) click to toggle source

Checks if class has mulitple versions available and picks one that matches the version option. @!visibility private

Calls superclass method
# File lib/mustermann/versions.rb, line 9
def new(*args, version: nil, **options)
  return super(*args, **options) unless versions.any?
  self[version].new(*args, **options)
end
version(*list, inherit_from: nil, &block) click to toggle source

Defines a new version. @!visibility private

# File lib/mustermann/versions.rb, line 22
def version(*list, inherit_from: nil, &block)
  superclass = self[inherit_from] || self
  subclass   = Class.new(superclass, &block)
  list.each { |v| versions[v] = subclass }
end
versions() click to toggle source

@return [Hash] version to subclass mapping. @!visibility private

# File lib/mustermann/versions.rb, line 16
def versions
  @versions ||= {}
end