Class: Ns::ServiceConfig
- Inherits:
-
Object
- Object
- Ns::ServiceConfig
- Defined in:
- lib/ns_service_pack/service_config.rb
Constant Summary collapse
- SERVICE_CONFIG_FILE =
'config/ns_services.yml'
- @@services =
{}
Class Method Summary collapse
- .load_services!(config_file = SERVICE_CONFIG_FILE) ⇒ Object
-
.service_url(service_key = '', params = {}, force_sub = true) ⇒ Object
/def.
Class Method Details
.load_services!(config_file = SERVICE_CONFIG_FILE) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ns_service_pack/service_config.rb', line 8 def self.load_services!(config_file = SERVICE_CONFIG_FILE) return unless File.exists?(config_file) service_configs = YAML.load(File.read(SERVICE_CONFIG_FILE)) @@services.merge!(service_configs[Rails.env]) #load common parts if exists if (common_parts = service_configs['common']).is_a?(Hash) common_parts.each do |k, v| @@services[k] = if v.is_a?(Array) if v.size == 2 v[0] = @@services[v[0].to_sym] Util.concat_url(v[0], v[1]) else raise "Invalid path!" end #/if else v end #/if end #/do end #/if @@services end |
.service_url(service_key = '', params = {}, force_sub = true) ⇒ Object
/def
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ns_service_pack/service_config.rb', line 30 def self.service_url(service_key = '', params = {}, force_sub = true) #fixed a bug here, using dup to avoid modify the original templages url_key = service_key.to_sym raise "Not found key:#{url_key} in the config file:#{SERVICE_CONFIG_FILE}" unless @@services.key?(url_key) the_url = services[url_key].to_s.dup rescue '' if force_sub && params[:id] the_url.sub!(':id', params[:id].to_s) end #TODO REMOVE THIS if force_sub && params[:customer_id] the_url.sub!(':customer_id', params[:customer_id].to_s) end block_given? ? yield(the_url) : the_url end |