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



111
112
113
114
115
116
# File 'lib/desert/manager.rb', line 111

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)


91
92
93
94
95
96
# File 'lib/desert/manager.rb', line 91

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



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

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



63
64
65
66
67
68
# File 'lib/desert/manager.rb', line 63

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



98
99
100
101
102
103
# File 'lib/desert/manager.rb', line 98

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
40
41
# 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, 'app','sweepers')
    paths << File.join(component_root, 'lib')
  end
  dependencies.load_paths.reverse_each do |path|
    paths << File.expand_path(path)
  end
  paths.uniq!
  paths
end

#plugin_exists?(name_or_directory) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/desert/manager.rb', line 70

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

#plugin_path(name) ⇒ Object



74
75
76
77
78
# File 'lib/desert/manager.rb', line 74

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



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

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



105
106
107
108
109
# File 'lib/desert/manager.rb', line 105

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