Class: Woro::Adapters::Gist
- Inherits:
-
Object
- Object
- Woro::Adapters::Gist
- Defined in:
- lib/woro/adapters/gist.rb
Instance Attribute Summary collapse
-
#gist_id ⇒ Object
readonly
Returns the value of attribute gist_id.
Class Method Summary collapse
-
.create_initial_remote_task(app_name, access_token = nil) ⇒ Object
Creates an initial welcome gist on project setup.
Instance Method Summary collapse
-
#extract_description(data) ⇒ Object
Extract description from gist’s data content string.
-
#gist ⇒ Hash
The Gist contains a collection of files.
-
#initialize(gist_id) ⇒ Gist
constructor
Create a new gist collection adapter.
-
#list_keys ⇒ Hash
Returns the list of files included in the Gist.
-
#push(task) ⇒ Object
Push this task’s file content to the Gist collection on the server.
-
#raw_url(file_name) ⇒ String
The raw url is a permalink for downloading the content rake task within the Gist as a file.
-
#read_template_file ⇒ String
Read the rake task template.
-
#retrieve_file_data(file_name) ⇒ Hash
Retrieves the data hash included in the gist under the #file_name.
-
#retrieve_gist(gist_id) ⇒ Hash
Retrieves metadata of the specified gist.
Constructor Details
#initialize(gist_id) ⇒ Gist
Create a new gist collection adapter
11 12 13 |
# File 'lib/woro/adapters/gist.rb', line 11 def initialize(gist_id) @gist_id = gist_id end |
Instance Attribute Details
#gist_id ⇒ Object (readonly)
Returns the value of attribute gist_id.
7 8 9 |
# File 'lib/woro/adapters/gist.rb', line 7 def gist_id @gist_id end |
Class Method Details
.create_initial_remote_task(app_name, access_token = nil) ⇒ Object
Creates an initial welcome gist on project setup
64 65 66 |
# File 'lib/woro/adapters/gist.rb', line 64 def self.create_initial_remote_task(app_name, access_token=nil) ::Gist.gist("Welcome to the Woro Task Repository for #{app_name}", filename: app_name, access_token: access_token) end |
Instance Method Details
#extract_description(data) ⇒ Object
Extract description from gist’s data content string.
- String
-
description string
71 72 73 |
# File 'lib/woro/adapters/gist.rb', line 71 def extract_description(data) Woro::TaskHelper.extract_description(data['content']) end |
#gist ⇒ Hash
The Gist contains a collection of files. These are stored and accessed on Github.
34 35 36 |
# File 'lib/woro/adapters/gist.rb', line 34 def gist @gist ||= retrieve_gist(gist_id) end |
#list_keys ⇒ Hash
Returns the list of files included in the Gist
17 18 19 |
# File 'lib/woro/adapters/gist.rb', line 17 def list_keys gist['files'] end |
#push(task) ⇒ Object
Push this task’s file content to the Gist collection on the server. Existing contents by the same #file_name will be overriden, but can be accessed via Github or Gist’s API.
24 25 26 27 28 29 |
# File 'lib/woro/adapters/gist.rb', line 24 def push(task) ::Gist.multi_gist({ task.file_name => task.read_task_file }, public: false, update: gist_id, output: :all) end |
#raw_url(file_name) ⇒ String
The raw url is a permalink for downloading the content rake task within the Gist as a file.
58 59 60 |
# File 'lib/woro/adapters/gist.rb', line 58 def raw_url(file_name) retrieve_file_data(file_name)['raw_url'] end |
#read_template_file ⇒ String
Read the rake task template
77 78 79 |
# File 'lib/woro/adapters/gist.rb', line 77 def read_template_file File.read(File.join(File.dirname(__FILE__), 'templates','task.rake') ) end |
#retrieve_file_data(file_name) ⇒ Hash
Retrieves the data hash included in the gist under the #file_name.
50 51 52 |
# File 'lib/woro/adapters/gist.rb', line 50 def retrieve_file_data(file_name) gist['files'][file_name] end |
#retrieve_gist(gist_id) ⇒ Hash
Retrieves metadata of the specified gist
41 42 43 44 45 |
# File 'lib/woro/adapters/gist.rb', line 41 def retrieve_gist(gist_id) service_url = "https://api.github.com/gists/#{gist_id}" response = Net::HTTP.get_response(URI.parse(service_url)) JSON.parse(response.body || '') end |