Class: Choosy::Version
- Inherits:
-
Object
- Object
- Choosy::Version
- Defined in:
- lib/choosy/version.rb
Instance Attribute Summary collapse
-
#date_format ⇒ Object
Returns the value of attribute date_format.
-
#version_file ⇒ Object
Returns the value of attribute version_file.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #date ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(version_file, date_format = '%d/%m/%Y') ⇒ Version
constructor
A new instance of Version.
- #major ⇒ Object
- #minor ⇒ Object
- #reload! ⇒ Object
- #tiny ⇒ Object
- #to_s ⇒ Object
- #version!(kind) ⇒ Object
Constructor Details
#initialize(version_file, date_format = '%d/%m/%Y') ⇒ Version
Returns a new instance of Version.
7 8 9 10 11 12 13 14 15 |
# File 'lib/choosy/version.rb', line 7 def initialize(version_file, date_format='%d/%m/%Y') if !File.file?(version_file) raise Choosy::ConfigurationError.new("No version file given: #{version_file}") end @version_file = version_file @date_format = date_format reload! end |
Instance Attribute Details
#date_format ⇒ Object
Returns the value of attribute date_format.
5 6 7 |
# File 'lib/choosy/version.rb', line 5 def date_format @date_format end |
#version_file ⇒ Object
Returns the value of attribute version_file.
5 6 7 |
# File 'lib/choosy/version.rb', line 5 def version_file @version_file end |
Class Method Details
.method_missing(method, *args, &block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/choosy/version.rb', line 79 def self.method_missing(method, *args, &block) if method.to_s =~ /^load_from_(.*)$/ parts = $1.split(/_/) parts.map! do |part| case part when 'here' then '.' when 'parent' then '..' else part end end basedir = if args.length == 0 # Find the path to the calling file # How awesome is this !? File.dirname(caller(1)[0].split(/:/)[0]) else args.join(File::Separator) end path = File.join(basedir, *parts) load_from(path) else super end end |
Instance Method Details
#<=>(other) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/choosy/version.rb', line 69 def <=>(other) if major >= other.major || minor >= other.minor || tiny >= other.tiny 1 elsif major <= other.major || minor <= other.minor || tiny <= other.tiny -1 else 0 end end |
#==(other) ⇒ Object
61 62 63 |
# File 'lib/choosy/version.rb', line 61 def ==(other) major == other.major && minor == other.minor && tiny == other.tiny end |
#date ⇒ Object
29 30 31 |
# File 'lib/choosy/version.rb', line 29 def date @contents[DATE] end |
#eql?(other) ⇒ Boolean
65 66 67 |
# File 'lib/choosy/version.rb', line 65 def eql?(other) self == other end |
#major ⇒ Object
25 26 27 |
# File 'lib/choosy/version.rb', line 25 def major @contents[VERSION][MAJOR] end |
#minor ⇒ Object
21 22 23 |
# File 'lib/choosy/version.rb', line 21 def minor @contents[VERSION][MINOR] end |
#reload! ⇒ Object
33 34 35 |
# File 'lib/choosy/version.rb', line 33 def reload! @contents = YAML.load_file(@version_file) end |
#tiny ⇒ Object
17 18 19 |
# File 'lib/choosy/version.rb', line 17 def tiny @contents[VERSION][TINY] end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/choosy/version.rb', line 57 def to_s "#{major}.#{minor}.#{tiny}" end |
#version!(kind) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/choosy/version.rb', line 37 def version!(kind) kind = kind.to_s unless VERSIONS.include?(kind) raise Choosy::VersionError.new("Wrong versioning schema: #{kind}") end VERSIONS.each do |vers| if vers == kind @contents[VERSION][kind] += 1 break else @contents[VERSION][vers] = 0 end end @contents[DATE] = Time.now.strftime(@date_format) File.open(@version_file, 'w') do |out| YAML.dump(@contents, out) end end |