class Answers::Plugin

Attributes

always_allow_access[RW]
class_name[RW]
controller[RW]
dashboard[RW]
directory[RW]
hide_from_menu[RW]
menu_match[RW]
name[RW]
pathname[RW]
plugin_activity[RW]
url[RW]

Public Class Methods

new() click to toggle source

Make this protected, so that only Plugin.register can use it.

# File lib/answers/plugin.rb, line 69
def initialize
  # provide a default pathname to where this plugin is using its lib directory.
  depth = RUBY_VERSION >= "1.9.2" ? 4 : 3
  self.pathname ||= Pathname.new(caller(depth).first.match("(.*)#{File::SEPARATOR}lib")[1])
end
register() { |plugin = self| ... } click to toggle source
# File lib/answers/plugin.rb, line 8
def self.register(&block)
  yield(plugin = self.new)

  raise "A plugin MUST have a name!: #{plugin.inspect}" if plugin.name.blank?

  # Set defaults.
  plugin.menu_match ||= %r{answers/#{plugin.name}(/.+?)?$}
  plugin.always_allow_access ||= false
  plugin.dashboard ||= false
  plugin.class_name ||= plugin.name.camelize

  # add the new plugin to the collection of registered plugins
  ::Answers::Plugins.registered << plugin
end

Public Instance Methods

activity=(activities) click to toggle source

Stores information that can be used to retrieve the latest activities of this plugin

# File lib/answers/plugin.rb, line 34
def activity=(activities)
  Answers.deprecate('Answers::Plugin#activity=', when: '3.1')
end
description() click to toggle source

Returns the internationalized version of the description

# File lib/answers/plugin.rb, line 29
def description
  ::I18n.translate(['answers', 'plugins', name, 'description'].join('.'))
end
highlighted?(params) click to toggle source

Used to highlight the current tab in the admin interface

# File lib/answers/plugin.rb, line 39
def highlighted?(params)
  !!(params[:controller].try(:gsub, "admin/", "") =~ menu_match) || (dashboard && params[:action] == 'error_404')
end
pathname=(value) click to toggle source
# File lib/answers/plugin.rb, line 43
def pathname=(value)
  value = Pathname.new(value) if value.is_a? String
  @pathname = value
end
title() click to toggle source

Returns the internationalized version of the title

# File lib/answers/plugin.rb, line 24
def title
  ::I18n.translate(['answers', 'plugins', name, 'title'].join('.'))
end