Module: Bricks::Loader
- Included in:
- Bricks
- Defined in:
- lib/bricks/loader.rb
Constant Summary collapse
- @@no_init =
false
Instance Method Summary collapse
-
#apply_patches(file_name = nil) ⇒ Object
FIXME: remove.
- #brick_path(brick) ⇒ Object
- #bricks ⇒ Object
- #bricks_folders ⇒ Object
- #fixtures_path_for(brick) ⇒ Object
- #foreach_brick ⇒ Object
- #load_bricks ⇒ Object
- #load_filename(filename) ⇒ Object
-
#load_zafu(mod) ⇒ Object
FIXME: remove when we can use Zena::Use.modules_for(‘Zafu’).
- #migrations_for(brick) ⇒ Object
- #models_paths ⇒ Object
-
#no_init ⇒ Object
Returns true if the Bricks code should not be executed (such as during the initial migrations, legacy cleanup, etc).
- #no_init=(v) ⇒ Object
-
#old_foreach_brick(&block) ⇒ Object
FIXME: remove.
-
#paths_for(sub_path) ⇒ Object
Find all paths matching ‘sub_path’ in the active bricks.
- #test_files ⇒ Object
- #zafu_tests ⇒ Object
Instance Method Details
#apply_patches(file_name = nil) ⇒ Object
FIXME: remove
71 72 73 74 75 76 77 78 79 |
# File 'lib/bricks/loader.rb', line 71 def apply_patches(file_name = nil) file_name ||= caller[0].split('/').last.split(':').first old_foreach_brick do |brick_path| patch_file = File.join(brick_path, 'patch', file_name) if File.exist?(patch_file) load patch_file end end end |
#brick_path(brick) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/bricks/loader.rb', line 44 def brick_path(brick) p = nil bricks_folders.each do |f| p = File.join(f, brick) return p if File.exist?(p) end return p end |
#bricks ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bricks/loader.rb', line 5 def bricks @@bricks ||= bricks_folders.map do |bricks_folder| if File.exist?(bricks_folder) Dir.entries(bricks_folder).sort.map do |brick| if Bricks::CONFIG[brick] File.join(bricks_folder, brick) else nil end end else nil end end.flatten.compact.uniq end |
#bricks_folders ⇒ Object
21 22 23 24 25 |
# File 'lib/bricks/loader.rb', line 21 def bricks_folders @@bricks_folders ||= [File.join(Zena::ROOT, 'bricks'), File.join(RAILS_ROOT, 'bricks')].uniq.reject do |f| !File.exist?(f) end end |
#fixtures_path_for(brick) ⇒ Object
40 41 42 |
# File 'lib/bricks/loader.rb', line 40 def fixtures_path_for(brick) File.join(brick_path(brick), 'zena', 'test', 'sites') end |
#foreach_brick ⇒ Object
99 100 101 102 103 |
# File 'lib/bricks/loader.rb', line 99 def foreach_brick bricks.each do |path| yield File.basename(path) end end |
#load_bricks ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/bricks/loader.rb', line 115 def load_bricks bricks.each do |path| path = File.join(path, 'lib') ActiveSupport::Dependencies.autoload_paths << path ActiveSupport::Dependencies.autoload_once_paths << path $LOAD_PATH << path end if @@no_init puts "=> Not executing bricks init code." return end # execute Zena.use module and load 'init' bricks.each do |path| mod = path.split('/').last mod_path = "bricks/#{mod}" if File.exist?("#{path}/lib/#{mod_path}.rb") # bricks/acl/lib/bricks/acl.rb require mod_path mod = eval "Bricks::#{mod.camelcase}" Zena.use mod init_rb = "#{path}/zena/init.rb" if File.exist?(init_rb) require init_rb end end end end |
#load_filename(filename) ⇒ Object
81 82 83 84 85 |
# File 'lib/bricks/loader.rb', line 81 def load_filename(filename) bricks.map {|f| Dir["#{f}/zena/#{filename}.rb"] }.flatten.each do |file| require file end end |
#load_zafu(mod) ⇒ Object
FIXME: remove when we can use Zena::Use.modules_for(‘Zafu’)
89 90 91 92 93 94 95 96 97 |
# File 'lib/bricks/loader.rb', line 89 def load_zafu(mod) Bricks::CONFIG.keys.each do |brick_name| begin mod.send(:include, eval("Bricks::#{brick_name.camelcase}::ZafuMethods")) rescue NameError # ignore end end end |
#migrations_for(brick) ⇒ Object
36 37 38 |
# File 'lib/bricks/loader.rb', line 36 def migrations_for(brick) File.join(brick_path(brick), 'zena', 'migrate') end |
#models_paths ⇒ Object
32 33 34 |
# File 'lib/bricks/loader.rb', line 32 def models_paths paths_for('models') end |
#no_init ⇒ Object
Returns true if the Bricks code should not be executed (such as during the initial migrations, legacy cleanup, etc).
111 112 113 |
# File 'lib/bricks/loader.rb', line 111 def no_init !Zena::Db.migrated_once? || @@no_init end |
#no_init=(v) ⇒ Object
105 106 107 |
# File 'lib/bricks/loader.rb', line 105 def no_init=(v) @@no_init = v end |
#old_foreach_brick(&block) ⇒ Object
FIXME: remove
64 65 66 67 68 |
# File 'lib/bricks/loader.rb', line 64 def old_foreach_brick(&block) bricks.each do |path| block.call(path) end end |
#paths_for(sub_path) ⇒ Object
Find all paths matching ‘sub_path’ in the active bricks.
28 29 30 |
# File 'lib/bricks/loader.rb', line 28 def paths_for(sub_path) bricks.map {|f| Dir["#{f}/#{sub_path}"] }.flatten end |
#test_files ⇒ Object
57 58 59 60 61 |
# File 'lib/bricks/loader.rb', line 57 def test_files paths_for('zena/test/unit/*_test.rb') + paths_for('zena/test/functional/*_test.rb') + paths_for('zena/test/integration/*_test.rb') end |
#zafu_tests ⇒ Object
53 54 55 |
# File 'lib/bricks/loader.rb', line 53 def zafu_tests paths_for('zena/test/zafu') end |