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
# 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



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

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



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

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

#clusterObject



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

def cluster
  @cluster
end

#logObject



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

def log
  @log
end

#processObject



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

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

#watchObject



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

def watch
  @watch
end