Module: Glaemscribe::API::ResourceManager
- Defined in:
- lib/api/resource_manager.rb
Constant Summary collapse
- MODE_PATH =
The same structure is kept within the gem
File.dirname(__FILE__) + "/../../glaemresources/modes/"
- MODE_EXT =
"glaem"
- CHARSET_PATH =
File.dirname(__FILE__) + "/../../glaemresources/charsets/"
- CHARSET_EXT =
"cst"
- ALL =
["*"]
- MODE_FILES =
[MODE_PATH + "*.#{MODE_EXT}"]
Class Method Summary collapse
- .available_mode_names ⇒ Object
- .charset(name) ⇒ Object
- .charset_name_from_file_path(file_path) ⇒ Object
- .class_for_post_processor_operator_name(operator_name) ⇒ Object
- .class_for_pre_processor_operator_name(operator_name) ⇒ Object
- .load_charsets(which_ones = ALL) ⇒ Object
- .load_modes(which_ones = ALL) ⇒ Object
- .loaded_charsets ⇒ Object
- .loaded_modes ⇒ Object
- .mode_name_from_file_path(file_path) ⇒ Object
- .p ⇒ Object
- .register_post_processor_class(operator_name, operator_class) ⇒ Object
- .register_pre_processor_class(operator_name, operator_class) ⇒ Object
Class Method Details
.available_mode_names ⇒ Object
44 45 46 47 48 |
# File 'lib/api/resource_manager.rb', line 44 def self.available_mode_names Dir.glob(MODE_FILES).map { |mode_file| self.mode_name_from_file_path(mode_file) } end |
.charset(name) ⇒ Object
129 130 131 |
# File 'lib/api/resource_manager.rb', line 129 def self.charset(name) @loaded_charsets[name] end |
.charset_name_from_file_path(file_path) ⇒ Object
84 85 86 |
# File 'lib/api/resource_manager.rb', line 84 def self.charset_name_from_file_path(file_path) File.basename(file_path,".*") end |
.class_for_post_processor_operator_name(operator_name) ⇒ Object
70 71 72 |
# File 'lib/api/resource_manager.rb', line 70 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
66 67 68 |
# File 'lib/api/resource_manager.rb', line 66 def self.class_for_pre_processor_operator_name(operator_name) @pre_processor_operator_classes[operator_name] end |
.load_charsets(which_ones = ALL) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/api/resource_manager.rb', line 108 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
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/api/resource_manager.rb', line 88 def self.load_modes(which_ones = ALL) which_ones = [which_ones] if(which_ones.is_a?(String)) Dir.glob(MODE_FILES) { |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_charsets ⇒ Object
54 55 56 |
# File 'lib/api/resource_manager.rb', line 54 def self.loaded_charsets @loaded_charsets end |
.loaded_modes ⇒ Object
50 51 52 |
# File 'lib/api/resource_manager.rb', line 50 def self.loaded_modes @loaded_modes end |
.mode_name_from_file_path(file_path) ⇒ Object
79 80 81 82 |
# File 'lib/api/resource_manager.rb', line 79 def self.mode_name_from_file_path(file_path) ext = (file_path =~ /\.glaem\.dev$/)?(".glaem.dev"):(".glaem") File.basename(file_path,ext) end |
.p ⇒ Object
74 75 76 77 |
# File 'lib/api/resource_manager.rb', line 74 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
62 63 64 |
# File 'lib/api/resource_manager.rb', line 62 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
58 59 60 |
# File 'lib/api/resource_manager.rb', line 58 def self.register_pre_processor_class(operator_name, operator_class) @pre_processor_operator_classes[operator_name] = operator_class end |