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 29 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 42 def inspect name end
name()
click to toggle source
@!visibility private
Calls superclass method
# File lib/mustermann/versions.rb, line 37 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 8 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 21 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 15 def versions @versions ||= {} end