Class: RequestMigrations::Version
- Inherits:
-
Object
- Object
- RequestMigrations::Version
- Includes:
- Comparable
- Defined in:
- lib/request_migrations/version.rb
Defined Under Namespace
Classes: Constraint
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
Returns a new instance of Version.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/request_migrations/version.rb', line 12 def initialize(version) raise UnsupportedVersionError, "version is unsupported: #{version}" unless version.in?(RequestMigrations.supported_versions) @format = RequestMigrations.config.version_format.to_sym @value = case @format when :semver Semverse::Version.coerce(version) when :date Date.parse(version) when :integer version.to_i when :float version.to_f when :string version.to_s else raise InvalidVersionFormatError, "invalid version format: #{@format} (must be one of: #{SUPPORTED_VERSION_FORMATS.join(',')}" end rescue Semverse::InvalidVersionFormat, Date::Error raise InvalidVersionError, "invalid #{@format} version given: #{version}" end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
9 10 11 |
# File 'lib/request_migrations/version.rb', line 9 def format @format end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
9 10 11 |
# File 'lib/request_migrations/version.rb', line 9 def value @value end |
Class Method Details
.coerce(version) ⇒ Object
40 41 42 |
# File 'lib/request_migrations/version.rb', line 40 def coerce(version) version.is_a?(self) ? version : new(version) end |