Class: MotiroReporter
- Inherits:
-
Object
- Object
- MotiroReporter
- Defined in:
- app/core/reporter.rb
Overview
A reporter is someone capable of going out for news
For a Motiro reporter, “going out” may include, but is not limited to, accessing the local file system, executing external processes and consulting the web
Direct Known Subclasses
CacheReporter, DarcsReporter, SubversionReporter, WikiReporter
Class Method Summary collapse
-
.add(code) ⇒ Object
Adds a button to this reporter’s toolbar.
-
.button ⇒ Object
A hash of buttons available for reporters.
-
.caching(switch) ⇒ Object
Turns caching on and off for the reporter.
- .reporter_name ⇒ Object
-
.title(title) ⇒ Object
Replaces the default title with a custom one.
Instance Method Summary collapse
- #buttons ⇒ Object
- #cache? ⇒ Boolean
- #channel_title ⇒ Object
- #latest_headline ⇒ Object
- #name ⇒ Object
- #params_for(rid) ⇒ Object
Class Method Details
.add(code) ⇒ Object
Adds a button to this reporter’s toolbar. Accepts a text parameter that will be fed into the ERB templates when generating web pages.
It is a better idea to use one of the buttons available on the buttons hash than to hard-code the button code.
58 59 60 |
# File 'app/core/reporter.rb', line 58 def self.add(code) write_inheritable_array 'buttons', [code] end |
.button ⇒ Object
A hash of buttons available for reporters
Usage : class MyReporter < MotiroReporter
add_button buttons[:older]
end
67 68 69 |
# File 'app/core/reporter.rb', line 67 def self. @@buttons ||= { :older => OLDER_BUTTON } end |
.caching(switch) ⇒ Object
Turns caching on and off for the reporter
Usage : class MyReporter < MotiroReporter
caching :off
end
76 77 78 |
# File 'app/core/reporter.rb', line 76 def self.caching(switch) define_method :cache? do; :off != switch; end end |
.reporter_name ⇒ Object
33 34 35 36 |
# File 'app/core/reporter.rb', line 33 def self.reporter_name class_name = self.name return class_name[0, class_name.size - 8].underscore end |
.title(title) ⇒ Object
Replaces the default title with a custom one. Example usage:
class MyReporter < MotiroReporter
title "This is my reporter's custom title"
end
MyReporter.new.channel_title => "This is my reporter's custom title"
If not called, a default title will be generated based on the class name
47 48 49 50 51 |
# File 'app/core/reporter.rb', line 47 def self.title(title) define_method :channel_title do title.t end end |
Instance Method Details
#buttons ⇒ Object
88 89 90 |
# File 'app/core/reporter.rb', line 88 def self.class.read_inheritable_attribute 'buttons' || [] end |
#cache? ⇒ Boolean
96 |
# File 'app/core/reporter.rb', line 96 def cache?; true; end |
#channel_title ⇒ Object
84 85 86 |
# File 'app/core/reporter.rb', line 84 def channel_title return 'Latest news from %s' / name.humanize end |
#latest_headline ⇒ Object
98 99 100 |
# File 'app/core/reporter.rb', line 98 def latest_headline return latest_headlines.first end |
#name ⇒ Object
80 81 82 |
# File 'app/core/reporter.rb', line 80 def name return self.class.reporter_name end |
#params_for(rid) ⇒ Object
92 93 94 |
# File 'app/core/reporter.rb', line 92 def params_for(rid) {:controller => 'report', :action => 'show', :reporter => name, :id => rid} end |