github_releases 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: becf719af0caba624f4045a612becc9ed5295c35
4
- data.tar.gz: 917446e7bcee76ebfc874a427a8784d1015cfb40
3
+ metadata.gz: 8df93686d5c35a861acdb0fd62da461a9f8690d8
4
+ data.tar.gz: 9c5e71e95a7cf628918e55c591b73e68ffbb2113
5
5
  SHA512:
6
- metadata.gz: 2d5ac9ddab28e18887208df0a14256b06ee032507cac358dbef842aa777a9b7dceec534c8492ae1c23db1353f5845e2cdd39a4bfa4d1a73c8b15b67899eaff32
7
- data.tar.gz: 32e0c001ef4339472e05792e314abc22f569b4bb43d8d7b5614c79d996659b838d9b3c813cc155516e801b755327fd24df2ad809e80fd3e82b4df12b1d38eca0
6
+ metadata.gz: c2792271d180d4b92309766c26379623f8f75952ca6d3dbcc5a123924c16fbb23f67d08f65552d78535e2a1c0249e4c10a367da02630edb33cd703421850dc7f
7
+ data.tar.gz: 16b740d878071b602019adb1aeac68b1ab9a4387ae0f75c5a6005bb10e5fb741b42cfba728074b52caaee7da170914e13168f6a78b905ded97de3b812829140e
data/README.md CHANGED
@@ -36,14 +36,24 @@ An app that utilizes Github's release feature
36
36
  end
37
37
 
38
38
  ```
39
+
40
+ 4. Set your GitHub API token in a GITHUB_API_TOKEN environment variable.
39
41
 
40
- 4. Install
42
+ 5. Install
41
43
 
42
44
  ```ruby
43
45
  rails g github_releases:install
44
46
  ```
45
47
 
46
48
  This mounts the engine at `/releases`.
49
+
50
+ If you're using a pure Rails app, and want to use the current_version view helper, add GithubReleases::ApplicationHelper to your ApplicationController.
51
+
52
+ ```ruby
53
+ class ApplicationController < ActionController::Base
54
+ helper GithubReleases::ApplicationHelper
55
+ end
56
+ ```
47
57
 
48
58
  ## Usage
49
59
 
@@ -52,6 +62,32 @@ releases in json. '/releases/latest' will expose the latest release to use in
52
62
  displaying your apps current version. You may also access any single release
53
63
  by id '/releases/:id'.
54
64
 
65
+ For pure Rails apps, you may access the current_version of your app with a view helper...
66
+
67
+ ```Ruby
68
+ <%= current_version %>
69
+ ```
70
+
71
+ Or if you don't want to add the helper module to your controller, you can call the class directly...
72
+
73
+ ```Ruby
74
+ <%= GithubReleases.release('latest')['tag_name'] %>
75
+ ```
76
+
77
+ **IMPORTANT** All calls to the GitHub API are cached. It's up to you to refresh the cache when releases should be updated. There are two ways to do this. Via the rake task...
78
+
79
+ ```
80
+ rake github_releases:refresh_cache
81
+ ```
82
+
83
+ Or via a Ruby class method...
84
+
85
+ ```Ruby
86
+ GithubReleases.refresh_cache
87
+ ```
88
+
89
+ One strategy is to run the rake task in a post deploy hook.
90
+
55
91
  ## Authors
56
92
 
57
93
  * Brian Bauer / [@bbauer](https://github.com/bbauer)
@@ -1,9 +1,13 @@
1
1
  class GithubReleases::ReleasesController < GithubReleases::ApplicationController
2
2
  def index
3
- render json: GithubReleases.releases, status: 200
3
+ render json: GithubReleases.all, status: 200
4
4
  end
5
5
 
6
6
  def show
7
- render json: GithubReleases.release(params[:id]), status: 200
7
+ render json: GithubReleases.find(params[:id]), status: 200
8
+ end
9
+
10
+ def current_version
11
+ render json: { version: GithubReleases.current_version }, status: 200
8
12
  end
9
13
  end
@@ -1,7 +1,4 @@
1
1
  module GithubReleases
2
2
  module ApplicationHelper
3
- def current_version
4
- GithubReleases.release('latest')['tag_name']
5
- end
6
3
  end
7
4
  end
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  GithubReleases::Engine.routes.draw do
2
+ get '/current_version', to: 'releases#current_version'
2
3
  get '/:id', to: 'releases#show'
3
4
  root 'releases#index'
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module GithubReleases
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -6,19 +6,23 @@ module GithubReleases
6
6
  LATEST_ID = 'latest'
7
7
 
8
8
  class << self
9
- def refresh_cache
10
- cache.write(RELEASES_KEY, get(endpoint))
11
- cache.write("#{RELEASE_KEY}-#{LATEST_ID}", get("#{endpoint}/#{LATEST_ID}"))
12
- end
13
-
14
- def releases
9
+ def all
15
10
  fetch(RELEASES_KEY, endpoint)
16
11
  end
17
12
 
18
- def release(id)
13
+ def find(id)
19
14
  fetch("#{RELEASE_KEY}-#{id}", "#{endpoint}/#{id}")
20
15
  end
21
16
 
17
+ def current_version
18
+ ENV['CURRENT_VERSION'] || find(LATEST_ID)['tag_name']
19
+ end
20
+
21
+ def refresh
22
+ cache.write(RELEASES_KEY, get(endpoint))
23
+ cache.write("#{RELEASE_KEY}-#{LATEST_ID}", get("#{endpoint}/#{LATEST_ID}"))
24
+ end
25
+
22
26
  private
23
27
 
24
28
  def fetch(key, resource)
@@ -1,6 +1,6 @@
1
1
  namespace :github_releases do
2
2
  desc 'Refreshes the cached API calls'
3
- task refresh_cache: :environment do
4
- GithubReleases.refresh_cache
3
+ task refresh: :environment do
4
+ GithubReleases.refresh
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_releases
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - bbauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-03 00:00:00.000000000 Z
11
+ date: 2015-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -104,7 +104,7 @@ files:
104
104
  - lib/github_releases/engine.rb
105
105
  - lib/github_releases/version.rb
106
106
  - lib/tasks/github_releases_tasks.rake
107
- - lib/tasks/refresh_cache.rake
107
+ - lib/tasks/refresh.rake
108
108
  homepage: ''
109
109
  licenses:
110
110
  - MIT