Class: Optipipe::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/optipipe/models/mapper.rb

Class Method Summary collapse

Class Method Details

.get_javascript_mappers(controller_path) ⇒ Object



4
5
6
# File 'lib/optipipe/models/mapper.rb', line 4

def get_javascript_mappers(controller_path)
  get_yaml_data('javascripts')[controller_path]
end

.get_stylesheet_mappers(controller_path) ⇒ Object



8
9
10
# File 'lib/optipipe/models/mapper.rb', line 8

def get_stylesheet_mappers(controller_path)
  get_yaml_data('stylesheets')[controller_path]
end

.load_yamls!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/optipipe/models/mapper.rb', line 12

def load_yamls!
  javascript_files = Dir.glob(Rails.root.join('app', 'assets', 'javascripts', 'optipipe', 'mappers', '*'))
  stylesheet_files = Dir.glob(Rails.root.join('app', 'assets', 'stylesheets', 'optipipe', 'mappers', '*'))

  mapper_data = {
    javascripts: {},
    stylesheets: {}
  }
  javascript_files.sort.each do |yaml_path|
    data = YAML.load(File.open(yaml_path))
    mapper_data[:javascripts][data['controller_path']] ||= []
    mapper_data[:javascripts][data['controller_path']] << data
  end
  stylesheet_files.sort.each do |yaml_path|
    data = YAML.load(File.open(yaml_path))
    mapper_data[:stylesheets][data['controller_path']] ||= []
    mapper_data[:stylesheets][data['controller_path']] << data
  end
  
  Kernel.send(:remove_const, :OPTIPIPE_MAPPER_DATA) if Kernel.const_defined?(:OPTIPIPE_MAPPER_DATA)
  Kernel.const_set(:OPTIPIPE_MAPPER_DATA, Marshal.load(Marshal.dump(mapper_data)))
end