Module: Bricks::Loader

Included in:
Bricks
Defined in:
lib/bricks/loader.rb

Constant Summary collapse

@@no_init =
false

Instance Method Summary collapse

Instance Method Details

#apply_patches(file_name = nil) ⇒ Object

FIXME: remove



75
76
77
78
79
80
81
82
83
# File 'lib/bricks/loader.rb', line 75

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



48
49
50
51
52
53
54
55
# File 'lib/bricks/loader.rb', line 48

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

#bricksObject



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_foldersObject



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



44
45
46
# File 'lib/bricks/loader.rb', line 44

def fixtures_path_for(brick)
  File.join(brick_path(brick), 'zena', 'test', 'sites')
end

#foreach_brickObject



103
104
105
106
107
# File 'lib/bricks/loader.rb', line 103

def foreach_brick
  bricks.each do |path|
    yield File.basename(path)
  end
end

#init_pathsObject



36
37
38
# File 'lib/bricks/loader.rb', line 36

def init_paths
  paths_for('zena/init.rb')
end

#load_bricksObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/bricks/loader.rb', line 119

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
  # load 'init'
  init_paths.each do |init_path|
    require init_path
  end
end

#load_filename(filename) ⇒ Object



85
86
87
88
89
# File 'lib/bricks/loader.rb', line 85

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’)



93
94
95
96
97
98
99
100
101
# File 'lib/bricks/loader.rb', line 93

def load_zafu(mod)
  Bricks::CONFIG.keys.each do |brick_name|
    begin
      mod.send(:include, eval("Bricks::#{brick_name.capitalize}::ZafuMethods"))
    rescue NameError
      # ignore
    end
  end
end

#migrations_for(brick) ⇒ Object



40
41
42
# File 'lib/bricks/loader.rb', line 40

def migrations_for(brick)
  File.join(brick_path(brick), 'zena', 'migrate')
end

#models_pathsObject



32
33
34
# File 'lib/bricks/loader.rb', line 32

def models_paths
  paths_for('models')
end

#no_initObject

Returns true if the Bricks code should not be executed (such as during the initial migrations, legacy cleanup, etc).



115
116
117
# File 'lib/bricks/loader.rb', line 115

def no_init
  !Zena::Db.migrated_once? || @@no_init
end

#no_init=(v) ⇒ Object



109
110
111
# File 'lib/bricks/loader.rb', line 109

def no_init=(v)
  @@no_init = v
end

#old_foreach_brick(&block) ⇒ Object

FIXME: remove



68
69
70
71
72
# File 'lib/bricks/loader.rb', line 68

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_filesObject



61
62
63
64
65
# File 'lib/bricks/loader.rb', line 61

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_testsObject



57
58
59
# File 'lib/bricks/loader.rb', line 57

def zafu_tests
  paths_for('zena/test/zafu')
end