Class: Refinery::Plugin

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#always_allow_accessObject

Returns the value of attribute always_allow_access.



6
7
8
# File 'lib/refinery/plugin.rb', line 6

def always_allow_access
  @always_allow_access
end

#class_nameObject

Returns the class name of the plugin



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

def class_name
  @class_name
end

#controllerObject

Returns the value of attribute controller.



6
7
8
# File 'lib/refinery/plugin.rb', line 6

def controller
  @controller
end

#dashboardObject

Returns the value of attribute dashboard.



6
7
8
# File 'lib/refinery/plugin.rb', line 6

def dashboard
  @dashboard
end

#descriptionObject (readonly)

Returns the internationalized version of the description



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

def description
  @description
end

#directoryObject

Returns the value of attribute directory.



6
7
8
# File 'lib/refinery/plugin.rb', line 6

def directory
  @directory
end

#hide_from_menuObject

Returns the value of attribute hide_from_menu.



6
7
8
# File 'lib/refinery/plugin.rb', line 6

def hide_from_menu
  @hide_from_menu
end

Returns a RegExp that matches, if the current page is part of the plugin.



73
74
75
# File 'lib/refinery/plugin.rb', line 73

def menu_match
  @menu_match
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/refinery/plugin.rb', line 6

def name
  @name
end

#pathnameObject

Returns the value of attribute pathname.



6
7
8
# File 'lib/refinery/plugin.rb', line 6

def pathname
  @pathname
end

#plugin_activityObject

Returns the value of attribute plugin_activity.



6
7
8
# File 'lib/refinery/plugin.rb', line 6

def plugin_activity
  @plugin_activity
end

#urlObject

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



83
84
85
# File 'lib/refinery/plugin.rb', line 83

def url
  @url
end

#versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/refinery/plugin.rb', line 6

def version
  @version
end

Class Method Details

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

Yields:

  • (plugin = self.new)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/refinery/plugin.rb', line 12

def self.register(&block)
  yield(plugin = self.new)

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

  # Set the root as Rails::Engine.called_from will always be
  #                 vendor/engines/refinery/lib/refinery
  new_called_from = begin
    # Remove the line number from backtraces making sure we don't leave anything behind
    call_stack = caller.map { |p| p.split(':')[0..-2].join(':') }
    File.dirname(call_stack.detect { |p| p !~ %r[railties[\w\-\.]*/lib/rails|rack[\w\-\.]*/lib/rack] })
  end

  klass = Class.new(Rails::Engine)
  klass.class_eval <<-RUBY
    def self.called_from; "#{new_called_from}"; end
  RUBY
  Object.const_set(plugin.class_name.to_sym, klass)
end

Instance Method Details

#activityObject

Retrieve information about how to access the latest activities of this plugin.



48
49
50
# File 'lib/refinery/plugin.rb', line 48

def activity
  self.plugin_activity ||= []
end

#activity=(activities) ⇒ Object

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



53
54
55
# File 'lib/refinery/plugin.rb', line 53

def activity=(activities)
  [activities].flatten.each { |activity| add_activity(activity) }
end

#always_allow_access?Boolean

Returns true, if the user doesn’t require plugin access

Returns:

  • (Boolean)


58
59
60
# File 'lib/refinery/plugin.rb', line 58

def always_allow_access?
  @always_allow_access ||= false
end

#dashboard?Boolean

Special property to indicate that this plugin is the dashboard plugin.

Returns:

  • (Boolean)


63
64
65
# File 'lib/refinery/plugin.rb', line 63

def dashboard?
  @dashboard ||= false
end

#highlighted?(params) ⇒ Boolean

Used to highlight the current tab in the admin interface

Returns:

  • (Boolean)


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

def highlighted?(params)
  (params[:controller] =~ self.menu_match) or (self.dashboard? and params[:action] == 'error_404')
end

#titleObject

Returns the internationalized version of the title



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

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