Class: Desert::Manager

Inherits:
Object show all
Defined in:
lib/desert/manager.rb

Overview

nodoc

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



17
18
19
20
# File 'lib/desert/manager.rb', line 17

def initialize
  @plugins = []
  @plugins_in_registration = []
end

Class Attribute Details

.instanceObject



4
5
6
# File 'lib/desert/manager.rb', line 4

def instance
  @instance ||= new
end

Instance Attribute Details

#loading_pluginObject (readonly)

Returns the value of attribute loading_plugin.



15
16
17
# File 'lib/desert/manager.rb', line 15

def loading_plugin
  @loading_plugin
end

#plugins_in_registrationObject (readonly)

Returns the value of attribute plugins_in_registration.



15
16
17
# File 'lib/desert/manager.rb', line 15

def plugins_in_registration
  @plugins_in_registration
end

Instance Method Details

#all_filesObject



109
110
111
112
113
114
# File 'lib/desert/manager.rb', line 109

def all_files
  Desert::Manager.load_paths.inject([]) do |all, load_path|
    all |= Dir["#{load_path}/**/*.rb"]
    all
  end
end

#directory_on_load_path?(dir_suffix) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
# File 'lib/desert/manager.rb', line 89

def directory_on_load_path?(dir_suffix)
  Desert::Manager.load_paths.each do |path|
    return true if File.directory?(File.join(path, dir_suffix))
  end
  return false
end

#files_on_load_path(file) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/desert/manager.rb', line 78

def files_on_load_path(file)
  desert_file_exists = false
  files = []
  load_paths.each do |path|
    full_path = File.join(path, file)
    full_path << '.rb' unless File.extname(full_path) == '.rb'
    files << full_path if File.exists?(full_path)
  end
  files
end

#find_plugin(name_or_directory) ⇒ Object



61
62
63
64
65
66
# File 'lib/desert/manager.rb', line 61

def find_plugin(name_or_directory)
  name = File.basename(File.expand_path(name_or_directory))
  plugins.find do |plugin|
    plugin.name == name
  end
end

#layout_pathsObject



96
97
98
99
100
101
# File 'lib/desert/manager.rb', line 96

def layout_paths
  layout_paths = plugins.reverse.collect do |plugin|
    plugin.layouts_path
  end
  layout_paths
end

#load_pathsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/desert/manager.rb', line 26

def load_paths
  paths = []
  plugin_paths.each do |component_root|
    paths << File.join(component_root, 'app')
    paths << File.join(component_root, 'app','models')
    paths << File.join(component_root, 'app','controllers')
    paths << File.join(component_root, 'app','helpers')
    paths << File.join(component_root, 'lib')
  end
  dependencies.load_paths.reverse.each do |path|
    paths << File.expand_path(path) unless paths.include?(File.expand_path(path))
  end
  paths
end

#plugin_exists?(name_or_directory) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/desert/manager.rb', line 68

def plugin_exists?(name_or_directory)
  !find_plugin(name_or_directory).nil?
end

#plugin_path(name) ⇒ Object



72
73
74
75
76
# File 'lib/desert/manager.rb', line 72

def plugin_path(name)
  plugin = find_plugin(name)
  return nil unless plugin
  plugin.path
end

#pluginsObject



22
23
24
# File 'lib/desert/manager.rb', line 22

def plugins
  @plugins.dup
end

#register_plugin(plugin_path) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/desert/manager.rb', line 41

def register_plugin(plugin_path)
  plugin = Plugin.new(plugin_path)
  @plugins_in_registration << plugin

  yield if block_given?

  dependencies.load_paths << plugin.models_path
  dependencies.load_paths << plugin.controllers_path
  dependencies.load_paths << plugin.helpers_path

  @plugins_in_registration.pop

  if existing_plugin = find_plugin(plugin.name)
    return existing_plugin
  end

  @plugins << plugin
  plugin
end

#require_all_filesObject



103
104
105
106
107
# File 'lib/desert/manager.rb', line 103

def require_all_files
  all_files.each do |file|
    require file
  end
end