Class: JsonVersioner
- Inherits:
-
Object
- Object
- JsonVersioner
- Defined in:
- lib/rake-extensions.rb
Instance Method Summary collapse
- #get_current_version ⇒ Object
- #get_next_version(jump) ⇒ Object
- #increment_version(jump) ⇒ Object
-
#initialize(version_dir) ⇒ JsonVersioner
constructor
A new instance of JsonVersioner.
- #update_version(new_version) ⇒ Object
Constructor Details
#initialize(version_dir) ⇒ JsonVersioner
Returns a new instance of JsonVersioner.
147 148 149 |
# File 'lib/rake-extensions.rb', line 147 def initialize(version_dir) @version_dir = version_dir end |
Instance Method Details
#get_current_version ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/rake-extensions.rb', line 155 def get_current_version() current_version = nil FileUtils.cd @version_dir, :verbose => false do ['package.json'].each do |file| text = File.read(file) if match = text.match(/^\s\s\"version\":\s\"(.*)\"/i) current_version = match.captures[0] end end end current_version end |
#get_next_version(jump) ⇒ Object
150 151 152 153 154 |
# File 'lib/rake-extensions.rb', line 150 def get_next_version(jump) current_version = get_current_version() v = Version.new(current_version) v.send(jump) end |
#increment_version(jump) ⇒ Object
167 168 169 170 171 |
# File 'lib/rake-extensions.rb', line 167 def increment_version(jump) next_version = get_next_version(jump) puts "increment version from #{get_current_version} ==> #{next_version}" update_version(next_version) end |
#update_version(new_version) ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/rake-extensions.rb', line 172 def update_version(new_version) FileUtils.cd @version_dir, :verbose => false do ['package.json'].each do |file| text = File.read(file) new_contents = text.gsub(/^\s\s\"version\":\s\"\d+\.\d+\.\d+\"/, " \"version\": \"#{new_version}\"") File.open(file, "w") { |f| f.puts new_contents } end end end |