ncupdater 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +69 -0
- data/lib/ncupdater/nccheck_version.rb +31 -0
- data/lib/ncupdater/ncupdate.rb +11 -0
- data/lib/ncupdater.rb +32 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5435fcd70581968d3e3fed09161d453cb952ac4
|
4
|
+
data.tar.gz: 160c6171cb492a0946a392213e52382d80c9ff43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 804637fc109d0668ef041632407379e6613cfa31cc24ac7b96728f2b88417d30e94852b89c67bff9ac120c8e30db9ad5d4ba2961a055ac3f12857b3bde7af007
|
7
|
+
data.tar.gz: eaed02ad50a512f2b391720a71e5a2b7f213aafd7e547f982d00781d2ef9e5c5704006a18a4243b1a6b64a03c11736a5b535e3ff17dce1fb58fba5be196737db
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# ncupdater
|
2
|
+
NCUpdater provides you with an easy way to update your ruby scripts. You specify a link to a small text file with latest version number, and the path of a .semver file in your project.
|
3
|
+
It will then check for updates every time your project starts. You can run update with a list of commands you would like to run.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
```bash
|
8
|
+
gem install ncupdater
|
9
|
+
```
|
10
|
+
|
11
|
+
## Example
|
12
|
+
|
13
|
+
### Basic usage
|
14
|
+
|
15
|
+
#### Example 1
|
16
|
+
|
17
|
+
This example will run the update when the script starts
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'ncupdater'
|
21
|
+
|
22
|
+
# Define commands to run the update
|
23
|
+
commands = {
|
24
|
+
:'Gem update' => 'gem update my-command',
|
25
|
+
:'Some other command' => 'ls -la'
|
26
|
+
}
|
27
|
+
|
28
|
+
# Init the NCUpdater class
|
29
|
+
# .semver is path to the location of a file with the local version in the semver format (http://semver.org/)
|
30
|
+
# The url is to a link with a text file with the latest version in semver format.
|
31
|
+
ncupdater = NCUpdater::new('.semver', 'http://LINK-TO-A-TEXT-FILE-WITH-NEW-VERSION', commands)
|
32
|
+
|
33
|
+
if ncupdater::new_version?
|
34
|
+
ncupdater::update
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
#### Example 2
|
39
|
+
|
40
|
+
This example will run the update if you provide "update" as first argument of your script. It also shows a message when the script starts that there are a newer version
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'ncupdater'
|
44
|
+
|
45
|
+
# Define commands to run the update
|
46
|
+
commands = {
|
47
|
+
:'Gem update' => 'gem update my-command',
|
48
|
+
:'Some other command' => 'ls -la'
|
49
|
+
}
|
50
|
+
|
51
|
+
# Init the NCUpdater class
|
52
|
+
# .semver is path to the location of a file with the local version in the semver format (http://semver.org/)
|
53
|
+
# The url is to a link with a text file with the latest version in semver format.
|
54
|
+
ncupdater = NCUpdater::new('.semver', 'http://LINK-TO-A-TEXT-FILE-WITH-NEW-VERSION', commands)
|
55
|
+
|
56
|
+
if ncupdater::new_version?
|
57
|
+
puts 'A new version is available. Please run the command as: ruby <my-script>.rb update to get the latest awesomeness'
|
58
|
+
end
|
59
|
+
|
60
|
+
if ARGV[0] == 'update'
|
61
|
+
ncupdater::update
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
## Todo
|
66
|
+
|
67
|
+
- Write some tests
|
68
|
+
- Write doc blocks
|
69
|
+
- Better error handling
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class NCCheckVersion
|
2
|
+
|
3
|
+
def check_for_updates(semver_path = '', remote_url = '')
|
4
|
+
@semver_path = semver_path
|
5
|
+
@remote_url = remote_url
|
6
|
+
|
7
|
+
local_version = Semantic::Version.new "#{current_version}"
|
8
|
+
newer_version = Semantic::Version.new "#{remote_version}"
|
9
|
+
|
10
|
+
if local_version < newer_version
|
11
|
+
return true
|
12
|
+
end
|
13
|
+
return false
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def current_version
|
18
|
+
File.open(@semver_path) {|f| f.readline}
|
19
|
+
end
|
20
|
+
|
21
|
+
def remote_version
|
22
|
+
uri = URI.parse( @remote_url )
|
23
|
+
|
24
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
25
|
+
request = Net::HTTP::Get.new(uri.path)
|
26
|
+
|
27
|
+
response = http.request(request)
|
28
|
+
response.body
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/ncupdater.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'colorize'
|
4
|
+
require 'semantic'
|
5
|
+
require 'shell-spinner'
|
6
|
+
|
7
|
+
library_files = Dir[File.join(File.dirname(__FILE__), '/ncupdater/*.rb')].sort
|
8
|
+
library_files.each do |file|
|
9
|
+
require file
|
10
|
+
end
|
11
|
+
|
12
|
+
class NCUpdater
|
13
|
+
|
14
|
+
def initialize(semver_path = 'test', remote_url = '', commands = '')
|
15
|
+
@semver_path = semver_path
|
16
|
+
@remote_url = remote_url
|
17
|
+
@commands = commands
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
if new_version?
|
22
|
+
NCUpdate::new::update(@commands)
|
23
|
+
else
|
24
|
+
puts 'You are already on latest version..'.colorize(:yellow)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def new_version?
|
29
|
+
NCCheckVersion::new::check_for_updates(@semver_path, @remote_url)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ncupdater
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Schwartz
|
8
|
+
- Sigurd Kristensen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colorize
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: shell-spinner
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: semantic
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: A small handy upgrade tool for ruby scripts. just provide a version file,
|
57
|
+
and a url for latest version, and the script will handle the rest
|
58
|
+
email:
|
59
|
+
- tech@nodes.dk
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- README.md
|
65
|
+
- lib/ncupdater.rb
|
66
|
+
- lib/ncupdater/ncupdate.rb
|
67
|
+
- lib/ncupdater/nccheck_version.rb
|
68
|
+
homepage: https://github.com/nodes-cloud/ncupdater
|
69
|
+
licenses: []
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.0.14.1
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Easy way to update any ruby script
|
91
|
+
test_files: []
|