Class: Prepare

Inherits:
Object
  • Object
show all
Defined in:
lib/aml/Prepare.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Prepare

Returns a new instance of Prepare.



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
# File 'lib/aml/Prepare.rb', line 3

def initialize(file)
  @log = []
  @cluster = false
  @file = []
  @watch = []
  # Load Core Bundle
  path = File.join(File.dirname(File.expand_path(__FILE__)),'core')
  add_file(File.join(path,'mixin.aml'),'mixin', 'core')
  add_watch(File.join(path,'method.rb'), 'method', 'core')
  # Load Local Bundles
  bundles = Definition.new(file, false)
  bundles.self[:hash].reject{|k|k[:bundle] == false or k[:bundle] == nil}.each do |bundle|
    if @file.select{|k|k[:bundle] == bundle[:bundle]}.count == 0
      path = File.join(File.dirname(file), bundle[:bundle])
      add_file(File.join(path,'mixin.aml'), 'mixin', bundle[:bundle])
      add_watch(File.join(path,'method.rb'), 'method', bundle[:bundle])
      # Load Only Required Partials
      bundles.self[:hash].reject{|k|k[:bundle] != bundle[:bundle]}.reject{|k|k[:type] != :partial}.each do |partial|
        add_file(File.join(path,'partial',partial[:name]+'.aml'), 'partial', bundle[:bundle], bundle[:name])
      end
    end
  end
  # Load Local File Mixin & Method
  path = File.join(File.dirname(file))
  add_file(File.join(path,'mixin.aml'), 'mixin')
  add_watch(File.join(path,'method.rb'), 'method')
  # Load Only Requird Local Partials
  bundles.self[:hash].select{|k|k[:type] == :partial and k[:bundle] == false}.each do |bundle|
    add_file(File.join(path,'partial',bundle[:name]+'.aml'), 'partial', bundle[:bundle], bundle[:name])
  end
  # Load Local File
  add_file(file,'base')
  
  @watch.concat(@file)
  process
end

Instance Method Details

#add_file(file, type, bundle = false, partial = false) ⇒ Object



39
40
41
# File 'lib/aml/Prepare.rb', line 39

def add_file(file, type, bundle=false, partial=false)
  @file << {:file=>file, :type=> type, :bundle=>bundle, :partial=>partial}
end

#add_watch(file, type, bundle = false) ⇒ Object



42
43
44
# File 'lib/aml/Prepare.rb', line 42

def add_watch(file, type, bundle=false)
  @watch << {:file=>file, :bundle=>bundle}
end

#clusterObject



53
54
55
# File 'lib/aml/Prepare.rb', line 53

def cluster
  @cluster
end

#logObject



50
51
52
# File 'lib/aml/Prepare.rb', line 50

def log
  @log
end

#processObject



45
46
47
48
49
# File 'lib/aml/Prepare.rb', line 45

def process
  @cluster = Cluster.new(@file)
  @cluster.process
  @log = cluster.log
end

#watchObject



56
57
58
# File 'lib/aml/Prepare.rb', line 56

def watch
  @watch
end