Class: PagesCore::Plugin

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

Direct Known Subclasses

PagesPlugin

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.called_fromObject

Returns the value of attribute called_from.



12
13
14
# File 'lib/pages_core/plugin.rb', line 12

def called_from
  @called_from
end

.pathsObject

Returns the value of attribute paths.



12
13
14
# File 'lib/pages_core/plugin.rb', line 12

def paths
  @paths
end

Class Method Details

.admin_menu_item(label, path, group = :custom, options = {}) ⇒ Object



29
30
31
# File 'lib/pages_core/plugin.rb', line 29

def admin_menu_item(label, path, group = :custom, options = {})
  PagesCore::AdminMenuItem.register(label, path, group, options)
end

.inherited(plugin) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pages_core/plugin.rb', line 14

def inherited(plugin)
  plugin.paths ||= default_paths
  plugin.called_from = begin
    # Remove the line number from backtraces making sure we
    # don't leave anything behind
    call_stack = caller.map { |p| p.sub(/:\d+.*/, "") }
    File.dirname(
      call_stack.detect do |p|
        p !~ %r{railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack}
      end
    )
  end
  super
end

.pluginsObject



33
34
35
36
37
38
39
# File 'lib/pages_core/plugin.rb', line 33

def plugins
  @plugins ||= ::PagesCore::Plugin.subclasses.map do |class_name|
    class_name.to_s.split("::").inject(Object) do |klass, m|
      klass.const_get(m)
    end
  end
end

Instance Method Details

#pathsObject



52
53
54
# File 'lib/pages_core/plugin.rb', line 52

def paths
  self.class.paths
end

#rootObject



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

def root
  @root ||= find_root_with_subfolder("app")
end