Class: Cognition::Plugins::Base
- Inherits:
-
Object
- Object
- Cognition::Plugins::Base
- Defined in:
- lib/cognition/plugins/base.rb
Direct Known Subclasses
Constant Summary collapse
- RENDER_DEFAULTS =
{ type: "html", extension: "erb" }
Class Attribute Summary collapse
-
.view_root ⇒ Object
Returns the value of attribute view_root.
Instance Attribute Summary collapse
-
#bot ⇒ Object
Returns the value of attribute bot.
-
#matchers ⇒ Object
Returns the value of attribute matchers.
Class Method Summary collapse
- .definitions ⇒ Object
-
.inherited(plugin) ⇒ Object
Inherited callback to set a class-level instance variable on the subclass, since we can’t use __FILE__ here, and have it use the subclass’s location.
- .match(trigger, action, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(bot = nil) ⇒ Base
constructor
A new instance of Base.
- #render(opts = {}) ⇒ Object
Constructor Details
Class Attribute Details
.view_root ⇒ Object
Returns the value of attribute view_root.
11 12 13 |
# File 'lib/cognition/plugins/base.rb', line 11 def view_root @view_root end |
Instance Attribute Details
#bot ⇒ Object
Returns the value of attribute bot.
26 27 28 |
# File 'lib/cognition/plugins/base.rb', line 26 def bot @bot end |
#matchers ⇒ Object
Returns the value of attribute matchers.
26 27 28 |
# File 'lib/cognition/plugins/base.rb', line 26 def matchers @matchers end |
Class Method Details
.definitions ⇒ Object
39 40 41 |
# File 'lib/cognition/plugins/base.rb', line 39 def self.definitions @definitions ||= [] end |
.inherited(plugin) ⇒ Object
Inherited callback to set a class-level instance variable on the subclass, since we can’t use __FILE__ here, and have it use the subclass’s location.
22 23 24 |
# File 'lib/cognition/plugins/base.rb', line 22 def self.inherited(plugin) plugin.view_root = File.dirname(caller[0].split(":", 2).first) end |
.match(trigger, action, options = {}) ⇒ Object
35 36 37 |
# File 'lib/cognition/plugins/base.rb', line 35 def self.match(trigger, action, = {}) definitions << [trigger, action, ] end |
Instance Method Details
#render(opts = {}) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/cognition/plugins/base.rb', line 43 def render(opts = {}) = RENDER_DEFAULTS.merge(opts) calling_method = caller[0][/`([^']*)'/, 1] template = [:template] || template_file(calling_method, [:type], [:extension]) Tilt.new(template).render(self, [:locals]) rescue Errno::ENOENT => e raise PluginTemplateNotFound, e end |