Class: Gasoline::Drop
- Inherits:
-
Object
- Object
- Gasoline::Drop
- Defined in:
- lib/gasoline/drop.rb
Overview
A drop of Gasoline is a glorified hash that knows how to retrieve the javascript needed to make the Campfire even shinier.
Since Github’s gists are pretty much the easiest way to share pieces of code, Drop uses them for all things JS.
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.new_from_yml(hash) ⇒ Object
Takes the hash as usually found in the Jerrycan and creates a drop from it.
Instance Method Summary collapse
-
#download_content ⇒ Object
Returns the javascript from the gist URL.
-
#header ⇒ Object
The header that will be displayed above the drop in the patched file.
-
#initialize(name, url, description) ⇒ Drop
constructor
A new instance of Drop.
-
#patch(force_refresh = false) ⇒ Object
Fetches the JS content and adds a header to it, ready to be inserted in the patchor file.
-
#raw_gist_url ⇒ Object
Returns the raw url for the specified gist.
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, url, description) ⇒ Drop
Returns a new instance of Drop.
12 13 14 15 16 |
# File 'lib/gasoline/drop.rb', line 12 def initialize(name, url, description) @name = name @url = url @description = description end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
10 11 12 |
# File 'lib/gasoline/drop.rb', line 10 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/gasoline/drop.rb', line 10 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
10 11 12 |
# File 'lib/gasoline/drop.rb', line 10 def url @url end |
Class Method Details
.new_from_yml(hash) ⇒ Object
Takes the hash as usually found in the Jerrycan and creates a drop from it.
Returns a Drop
30 31 32 |
# File 'lib/gasoline/drop.rb', line 30 def self.new_from_yml(hash) new(hash[:name], hash[:url], hash[:description]) end |
Instance Method Details
#download_content ⇒ Object
Returns the javascript from the gist URL.
40 41 42 43 |
# File 'lib/gasoline/drop.rb', line 40 def download_content puts "Downloading #{@name} (#{@url})" open(raw_gist_url).read end |
#header ⇒ Object
The header that will be displayed above the drop in the patched file.
Returns a String
49 50 51 52 53 54 55 56 57 |
# File 'lib/gasoline/drop.rb', line 49 def header <<HEADER /* * #{@name} * #{@description} * */ HEADER end |
#patch(force_refresh = false) ⇒ Object
Fetches the JS content and adds a header to it, ready to be inserted in the patchor file.
force_refresh - true will redownload the JS
Returns a String
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gasoline/drop.rb', line 65 def patch(force_refresh = false) @js ||= download_content @js = download_content if force_refresh <<PATCH #{header} #{@js} // console.log("Loaded #{@name}"); PATCH rescue => error puts " -> #{error.}" nil end |
#raw_gist_url ⇒ Object
Returns the raw url for the specified gist
35 36 37 |
# File 'lib/gasoline/drop.rb', line 35 def raw_gist_url [@url, "raw"].join("/") end |
#to_hash ⇒ Object
22 23 24 |
# File 'lib/gasoline/drop.rb', line 22 def to_hash {:name => @name, :url => @url, :description => @description} end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/gasoline/drop.rb', line 18 def to_s "%s: %s" % [@name, @description] end |