class Refinery::Plugin

Attributes

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

Public Class Methods

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

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

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

  # add the new plugin to the collection of registered plugins
  ::Refinery::Plugins.registered.unshift(plugin).uniq!(&:name)
end

Public Instance Methods

description() click to toggle source

Returns the internationalized version of the description

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

Used to highlight the current tab in the admin interface

# File lib/refinery/plugin.rb, line 33
def highlighted?(params)
  !!(params[:controller].try(:gsub, "admin/", "") =~ menu_match)
end
landable?() click to toggle source
# File lib/refinery/plugin.rb, line 42
def landable?
  !hide_from_menu && url.present?
end
pathname=(value) click to toggle source
# File lib/refinery/plugin.rb, line 37
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/refinery/plugin.rb, line 23
def title
  ::I18n.translate(['refinery', 'plugins', name, 'title'].join('.'))
end

Private Instance Methods

build_url() click to toggle source
# File lib/refinery/plugin.rb, line 67
def build_url
  action = controller.presence ||
           directory.to_s.split('/').pop.presence ||
           name

  { controller: "refinery/admin/#{action}" }
end