Class: Spree::ExtensionLoader
Defined Under Namespace
Classes: DependenciesObserver
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Simpleton
included
Constructor Details
Returns a new instance of ExtensionLoader.
27
28
29
|
# File 'lib/spree/extension_loader.rb', line 27
def initialize
self.extensions = []
end
|
Instance Attribute Details
#extensions ⇒ Object
Returns the value of attribute extensions.
25
26
27
|
# File 'lib/spree/extension_loader.rb', line 25
def extensions
@extensions
end
|
#initializer ⇒ Object
Returns the value of attribute initializer.
25
26
27
|
# File 'lib/spree/extension_loader.rb', line 25
def initializer
@initializer
end
|
Instance Method Details
#activate_extensions ⇒ Object
Also known as:
reactivate
91
92
93
94
95
96
|
# File 'lib/spree/extension_loader.rb', line 91
def activate_extensions
initializer.initialize_framework_views
extensions.each &:activate
end
|
#add_controller_paths ⇒ Object
58
59
60
|
# File 'lib/spree/extension_loader.rb', line 58
def add_controller_paths
configuration.controller_paths.concat(controller_paths)
end
|
#add_extension_paths ⇒ Object
43
44
45
46
47
48
|
# File 'lib/spree/extension_loader.rb', line 43
def add_extension_paths
extension_load_paths.reverse_each do |path|
configuration.load_paths.unshift path
$LOAD_PATH.unshift path
end
end
|
#add_locale_paths ⇒ Object
66
67
68
|
# File 'lib/spree/extension_loader.rb', line 66
def add_locale_paths
configuration.i18n.load_path.concat(locale_paths)
end
|
#add_plugin_paths ⇒ Object
50
51
52
|
# File 'lib/spree/extension_loader.rb', line 50
def add_plugin_paths
configuration.plugin_paths.concat plugin_paths
end
|
#configuration ⇒ Object
31
32
33
|
# File 'lib/spree/extension_loader.rb', line 31
def configuration
initializer.configuration
end
|
#controller_paths ⇒ Object
54
55
56
|
# File 'lib/spree/extension_loader.rb', line 54
def controller_paths
extensions.map { |extension| "#{extension.root}/app/controllers" }.select { |d| File.directory?(d) }
end
|
#extension_load_paths ⇒ Object
35
36
37
|
# File 'lib/spree/extension_loader.rb', line 35
def extension_load_paths
load_extension_roots.map { |extension| load_paths_for(extension) }.flatten
end
|
#load_extension_roots ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/spree/extension_loader.rb', line 108
def load_extension_roots
@load_extension_roots ||= unless configuration.extensions.empty?
select_extension_roots
else
[]
end
end
|
#load_extensions ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/spree/extension_loader.rb', line 75
def load_extensions
@observer ||= DependenciesObserver.new(configuration).observe(ActiveSupport::Dependencies)
self.extensions = load_extension_roots.map do |root|
begin
extension_file = "#{File.basename(root).sub(/^\d+_/,'')}_extension"
extension = extension_file.camelize.constantize
extension.unloadable
extension.root = root
extension
rescue LoadError, NameError => e
$stderr.puts "Could not load extension from file: #{extension_file}.\n#{e.inspect}"
nil
end
end.compact
end
|
#locale_paths ⇒ Object
62
63
64
|
# File 'lib/spree/extension_loader.rb', line 62
def locale_paths
load_extension_roots.map { |extension| Dir[File.join("#{extension}/config/locales" , '*.{rb,yml}')] }.flatten
end
|
#plugin_paths ⇒ Object
39
40
41
|
# File 'lib/spree/extension_loader.rb', line 39
def plugin_paths
load_extension_roots.map {|extension| "#{extension}/vendor/plugins" }.select {|d| File.directory?(d) }
end
|
#run_initializers ⇒ Object
99
100
101
102
103
104
105
106
|
# File 'lib/spree/extension_loader.rb', line 99
def run_initializers
load_extension_roots.each do |extension_path|
Dir["#{extension_path}/config/initializers/**/*.rb"].sort.each do |initializer|
RAILS_DEFAULT_LOGGER.info "INFO: Loading initializer #{initializer}"
load(initializer)
end
end
end
|
#view_paths ⇒ Object
70
71
72
|
# File 'lib/spree/extension_loader.rb', line 70
def view_paths
extensions.map { |extension| "#{extension.root}/app/views" }.select { |d| File.directory?(d) }
end
|