Class: Refinery::Plugin

Inherits:
Object
  • Object
show all
Defined in:
core/lib/refinery/plugin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugin

Returns a new instance of Plugin



68
69
70
71
72
# File 'core/lib/refinery/plugin.rb', line 68

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

Instance Attribute Details

#always_allow_accessObject

Returns the value of attribute always_allow_access



4
5
6
# File 'core/lib/refinery/plugin.rb', line 4

def always_allow_access
  @always_allow_access
end

#class_nameObject

Returns the value of attribute class_name



4
5
6
# File 'core/lib/refinery/plugin.rb', line 4

def class_name
  @class_name
end

#controllerObject

Returns the value of attribute controller



4
5
6
# File 'core/lib/refinery/plugin.rb', line 4

def controller
  @controller
end

#directoryObject

Returns the value of attribute directory



4
5
6
# File 'core/lib/refinery/plugin.rb', line 4

def directory
  @directory
end

#hide_from_menuObject

Returns the value of attribute hide_from_menu



4
5
6
# File 'core/lib/refinery/plugin.rb', line 4

def hide_from_menu
  @hide_from_menu
end

Returns the value of attribute menu_match



4
5
6
# File 'core/lib/refinery/plugin.rb', line 4

def menu_match
  @menu_match
end

#nameObject

Returns the value of attribute name



4
5
6
# File 'core/lib/refinery/plugin.rb', line 4

def name
  @name
end

#pathnameObject

Returns the value of attribute pathname



4
5
6
# File 'core/lib/refinery/plugin.rb', line 4

def pathname
  @pathname
end

#urlObject

Returns a hash that can be used to create a url that points to the administration part of the plugin.



56
57
58
# File 'core/lib/refinery/plugin.rb', line 56

def url
  @url
end

Class Method Details

.register {|plugin = new| ... } ⇒ Object

Yields:

  • (plugin = new)

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'core/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

Instance Method Details

#activity=(_) ⇒ Object

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



33
34
35
# File 'core/lib/refinery/plugin.rb', line 33

def activity=(_)
  Refinery.deprecate('Refinery::Plugin#activity=', when: '3.1')
end

#dashboard=(_) ⇒ Object



37
38
39
# File 'core/lib/refinery/plugin.rb', line 37

def dashboard=(_)
  Refinery.deprecate('Refinery::Plugin#dashboard=', when: '3.1')
end

#descriptionObject

Returns the internationalized version of the description



28
29
30
# File 'core/lib/refinery/plugin.rb', line 28

def description
  ::I18n.translate(['refinery', 'plugins', name, 'description'].join('.'))
end

#highlighted?(params) ⇒ Boolean

Used to highlight the current tab in the admin interface

Returns:

  • (Boolean)


42
43
44
# File 'core/lib/refinery/plugin.rb', line 42

def highlighted?(params)
  !!(params[:controller].try(:gsub, "admin/", "") =~ menu_match)
end

#landable?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'core/lib/refinery/plugin.rb', line 51

def landable?
  !hide_from_menu && url.present?
end

#titleObject

Returns the internationalized version of the title



23
24
25
# File 'core/lib/refinery/plugin.rb', line 23

def title
  ::I18n.translate(['refinery', 'plugins', name, 'title'].join('.'))
end