Class: GreenSMS::API::ModuleLoader
- Inherits:
-
Object
- Object
- GreenSMS::API::ModuleLoader
- Defined in:
- lib/greensms/api/module_loader.rb
Instance Method Summary collapse
-
#initialize ⇒ ModuleLoader
constructor
A new instance of ModuleLoader.
- #register_modules(shared_options, filters = {}) ⇒ Object
Constructor Details
#initialize ⇒ ModuleLoader
Returns a new instance of ModuleLoader.
8 9 10 |
# File 'lib/greensms/api/module_loader.rb', line 8 def initialize() @module_map = {} end |
Instance Method Details
#register_modules(shared_options, filters = {}) ⇒ Object
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/greensms/api/module_loader.rb', line 12 def register_modules(, filters = {}) if filters.nil? filters = {} end current_version = ["version"] modules = GreenSMS::MODULES modules.each do |module_name, module_info| if !@module_map.has_key?(module_name.to_sym) @module_map[module_name] = {} end module_versions = module_info["versions"] module_schema = nil is_static_module = filters.has_key?("load_static") && module_info.has_key?("static") && filters["load_static"] == true && module_info["static"] = true next if is_static_module module_versions.each do |version, version_functions| if !@module_map[module_name].has_key?(version) @module_map[module_name][version] = {} end version_functions.each do |function_name, definition| if !@module_map[module_name][version].has_key?(function_name) @module_map[module_name][version][function_name] = {} end module_schema = nil schema_exists = module_info.has_key?("schema") && module_info["schema"].has_key?(version) && module_info["schema"][version].has_key?(function_name) if schema_exists == true module_schema = module_info["schema"][version][function_name] end url_args = [] if !module_info.has_key?("static") || module_info["static"] != true url_args.append(module_name) end url_args.append(function_name) api_url = GreenSMS.build_url(["base_url"], url_args) @module_map[module_name][version][function_name] = module_api( shared_options: , api_url: api_url, definition: definition, module_schema: module_schema, module_name: module_name, function_name: function_name, ) if version == current_version @module_map[module_name][function_name] = @module_map[module_name][version][function_name] end if module_info.has_key?("static") && module_info["static"] == true @module_map[function_name] = @module_map[module_name][version][function_name] @module_map.delete(module_name) end end end end return @module_map end |