Module: DashFu::Mario
- Included in:
- Backtweets, Github, GithubIssues, RubyGems
- Defined in:
- lib/dash-fu/mario.rb,
lib/dash-fu/marios/github.rb,
lib/dash-fu/marios/ruby_gems.rb,
lib/dash-fu/marios/backtweets.rb,
lib/dash-fu/marios/github_issues.rb
Overview
The README covers it all.
Defined Under Namespace
Modules: ClassMethods Classes: Backtweets, Github, GithubIssues, RubyGems
Class Attribute Summary collapse
-
.api_keys ⇒ Object
API keys (see instance method api_key).
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
-
.all ⇒ Object
Returns all available marios.
-
.find(id) ⇒ Object
Returns Mario by its identifier.
- .included(klass) ⇒ Object
-
.load_marios(path = File.dirname(__FILE__) + "/marios") ⇒ Object
Loads all the Marios from the given directory.
Instance Method Summary collapse
-
#description ⇒ Object
Returns additional information about this source.
-
#display ⇒ Object
This method returns a hash with two values: * inputs – HTML fragment for a setup form * notes – HTML fragment for setup notes.
-
#meta(source) ⇒ Object
Returns meta-data to be displayed alongside any other data.
-
#name ⇒ Object
Returns the display name for this Mario.
-
#register(source, url) ⇒ Object
Called to register a Webhook (for sources that need it).
-
#setup(source, params) ⇒ Object
Called to setup a new source with parameters from the HTML form (see #display).
-
#unregister(source, url) ⇒ Object
Called to unregister a Webhook (for sources that don’t need it).
-
#update(source, request, &block) ⇒ Object
Called to update the source.
-
#validate(source) ⇒ Object
Called to validate the source.
Class Attribute Details
.api_keys ⇒ Object
API keys (see instance method api_key).
42 43 44 |
# File 'lib/dash-fu/mario.rb', line 42 def api_keys @api_keys end |
.logger ⇒ Object
Returns the value of attribute logger.
14 15 16 |
# File 'lib/dash-fu/mario.rb', line 14 def logger @logger end |
Class Method Details
.all ⇒ Object
Returns all available marios.
17 18 19 |
# File 'lib/dash-fu/mario.rb', line 17 def all @marios ||= {} end |
.find(id) ⇒ Object
Returns Mario by its identifier.
22 23 24 |
# File 'lib/dash-fu/mario.rb', line 22 def find(id) all[id] end |
.included(klass) ⇒ Object
44 45 46 |
# File 'lib/dash-fu/mario.rb', line 44 def included(klass) klass.extend ClassMethods end |
.load_marios(path = File.dirname(__FILE__) + "/marios") ⇒ Object
Loads all the Marios from the given directory. The Mario identifier is derived from the filename (e.g. all/my_hero.rb becomes “my_hero”). The Mario class must map to the source identifier within the Mario module, e.g. DashFu::Mario::MyHero).
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dash-fu/mario.rb', line 30 def load_marios(path = File.dirname(__FILE__) + "/marios") Dir["#{path}/*.rb"].each do |file| id = File.basename(file, ".rb") fail "Mario #{id} already loaded" if all[id] load file klass = Mario.const_get(id.camelize) all[id] = klass.new logger.info "Loaded Mario #{id}: #{klass}" end end |
Instance Method Details
#description ⇒ Object
Returns additional information about this source.
A good description helps the user identity source and decide whether or not to use it.
Uses the resource ‘description’.
72 73 74 |
# File 'lib/dash-fu/mario.rb', line 72 def description resources["description"] end |
#display ⇒ Object
This method returns a hash with two values:
-
inputs – HTML fragment for a setup form
-
notes – HTML fragment for setup notes
Uses the resources ‘inputs’ and ‘notes’.
81 82 83 |
# File 'lib/dash-fu/mario.rb', line 81 def display { :inputs=>resources["inputs"], :notes=>resources["notes"] } end |
#meta(source) ⇒ Object
Returns meta-data to be displayed alongside any other data. This method should return an array of hashes, each with the keys title (optional), text and url (optional). Good meta-data provides timely and relevant information that is not available in the raw data.
117 118 119 |
# File 'lib/dash-fu/mario.rb', line 117 def (source) [] end |
#name ⇒ Object
Returns the display name for this Mario.
Uses the resource ‘name’, and fallbacks on the class name (e.g Mario::OneUp becomes “One Up”).
62 63 64 |
# File 'lib/dash-fu/mario.rb', line 62 def name resources["name"] || mario_id.titleize end |
#register(source, url) ⇒ Object
Called to register a Webhook (for sources that need it)
98 99 |
# File 'lib/dash-fu/mario.rb', line 98 def register(source, url) end |
#setup(source, params) ⇒ Object
Called to setup a new source with parameters from the HTML form (see #display). If there are any missing values, report them when #validate is called.
88 89 |
# File 'lib/dash-fu/mario.rb', line 88 def setup(source, params) end |
#unregister(source, url) ⇒ Object
Called to unregister a Webhook (for sources that don’t need it).
110 111 |
# File 'lib/dash-fu/mario.rb', line 110 def unregister(source, url) end |
#update(source, request, &block) ⇒ Object
Called to update the source. This method will be called periodically with a source and a block. When triggered by a Webhook, it will be called with source, Rack::Request and a block. It can yield to the block any number of times with any combination of the supported named arguments for updating the source.
106 107 |
# File 'lib/dash-fu/mario.rb', line 106 def update(source, request, &block) end |
#validate(source) ⇒ Object
Called to validate the source. If there are any error, raise an exception. A good error message will help the user understand which value is missing or invalid and how to correct that.
94 95 |
# File 'lib/dash-fu/mario.rb', line 94 def validate(source) end |