forked from bborn/eschaton
/
slice_loader.rb
55 lines (43 loc) · 1.75 KB
/
slice_loader.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module Eschaton
class SliceLoader # :nodoc:
# Loads all slices found using slice_locations and extends relevant objects.
def self.load
self.slice_locations.each do |slice_location|
mixin_slice_extentions slice_location
end
end
private
# Returns all the locations in which eschaton slices are located.
def self.slice_locations
locations = []
locations << "#{File.dirname(__FILE__)}/../../slices"
locations << "#{RAILS_ROOT}/lib/eschaton_slices"
locations.collect{|location|
Dir["#{location}/*"]
}.flatten
end
def self.mixin_slice_extentions(location)
_logger_info "loading slice '#{File.basename(location)}'"
Eschaton.dependencies.load_paths << location
Dir["#{location}/*.rb"].each do |file|
Eschaton.dependencies.require file
end
# Generator extentions
mixin_extentions :path => location, :pattern => /([a-z_\d]*_generator_ext).rb/,
:extend => ActionView::Helpers::PrototypeHelper::JavaScriptGenerator
# View extentions
mixin_extentions :path => location, :pattern => /([a-z_\d]*_view_ext).rb/,
:extend => ActionView::Base
# Controller extentions
mixin_extentions :path => location, :pattern => /([a-z_\d]*_controller_ext).rb/,
:extend => ActionController::Base
end
def self.mixin_extentions(options)
Dir["#{options[:path]}/*.rb"].each do |file|
if module_name = options[:pattern].match(file)
options[:extend].extend_with_slice module_name[1].camelize.constantize
end
end
end
end
end