Module: Glaemscribe::API::ResourceManager

Defined in:
lib/api/resource_manager.rb

Constant Summary collapse

MODE_PATH =
File.dirname(__FILE__) + "/../../glaemresources/modes/"
MODE_EXT =
"glaem"
CHARSET_PATH =
File.dirname(__FILE__) + "/../../glaemresources/charsets/"
CHARSET_EXT =
"cst"
ALL =
["*"]

Class Method Summary collapse

Class Method Details

.available_mode_namesObject



40
41
42
43
44
# File 'lib/api/resource_manager.rb', line 40

def self.available_mode_names
  Dir.glob(MODE_PATH + "*.#{MODE_EXT}").map { |mode_file|     
    self.mode_name_from_file_path(mode_file)
  }
end

.charset(name) ⇒ Object



124
125
126
# File 'lib/api/resource_manager.rb', line 124

def self.charset(name)
  @loaded_charsets[name]
end

.charset_name_from_file_path(file_path) ⇒ Object



79
80
81
# File 'lib/api/resource_manager.rb', line 79

def self.charset_name_from_file_path(file_path)
  File.basename(file_path,".*")
end

.class_for_post_processor_operator_name(operator_name) ⇒ Object



66
67
68
# File 'lib/api/resource_manager.rb', line 66

def self.class_for_post_processor_operator_name(operator_name)
  @post_processor_operator_classes[operator_name]
end

.class_for_pre_processor_operator_name(operator_name) ⇒ Object



62
63
64
# File 'lib/api/resource_manager.rb', line 62

def self.class_for_pre_processor_operator_name(operator_name)
  @pre_processor_operator_classes[operator_name]
end

.load_charsets(which_ones = ALL) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/api/resource_manager.rb', line 103

def self.load_charsets(which_ones = ALL)

  which_ones = [which_ones] if(which_ones.is_a?(String))  
    
  Dir.glob(CHARSET_PATH + "*.#{CHARSET_EXT}") { |charset_file|

    charset_name = self.charset_name_from_file_path(charset_file)
    
    next if(which_ones != ALL && !which_ones.include?(charset_name))
    next if(@loaded_charsets.include? charset_name) # Don't load a charset twice
  
    API::Debug::log("*" * 20)
    API::Debug::log("Parsing Charset : #{charset_name}")
    API::Debug::log("*" * 20)
  
    charset = API::CharsetParser.new().parse(charset_file)
    
    @loaded_charsets[charset.name] = charset if charset 
  } 
end

.load_modes(which_ones = ALL) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/api/resource_manager.rb', line 83

def self.load_modes(which_ones = ALL)
  
  which_ones = [which_ones] if(which_ones.is_a?(String))  
    
  Dir.glob(MODE_PATH + "*.#{MODE_EXT}") { |mode_file|

    mode_name = self.mode_name_from_file_path(mode_file)
   
    next if(which_ones != ALL && !which_ones.include?(mode_name))
    next if(@loaded_modes.include? mode_name) # Don't load a charset twice
    
    API::Debug::log("*" * 20)
    API::Debug::log("Parsing Mode : #{mode_name}")
    API::Debug::log("*" * 20)
  
    mode = API::ModeParser.new().parse(mode_file)
    @loaded_modes[mode.name] = mode if mode 
  }  
end

.loaded_charsetsObject



50
51
52
# File 'lib/api/resource_manager.rb', line 50

def self.loaded_charsets
  @loaded_charsets
end

.loaded_modesObject



46
47
48
# File 'lib/api/resource_manager.rb', line 46

def self.loaded_modes
  @loaded_modes
end

.mode_name_from_file_path(file_path) ⇒ Object



75
76
77
# File 'lib/api/resource_manager.rb', line 75

def self.mode_name_from_file_path(file_path)
  File.basename(file_path,".*")
end

.pObject



70
71
72
73
# File 'lib/api/resource_manager.rb', line 70

def self.p
  puts @pre_processor_operator_classes.inspect
  puts @post_processor_operator_classes.inspect        
end

.register_post_processor_class(operator_name, operator_class) ⇒ Object



58
59
60
# File 'lib/api/resource_manager.rb', line 58

def self.register_post_processor_class(operator_name, operator_class)
  @post_processor_operator_classes[operator_name] = operator_class
end

.register_pre_processor_class(operator_name, operator_class) ⇒ Object



54
55
56
# File 'lib/api/resource_manager.rb', line 54

def self.register_pre_processor_class(operator_name, operator_class)
  @pre_processor_operator_classes[operator_name] = operator_class
end