Class: MnUtilsGlobal::Gui
- Inherits:
-
Object
- Object
- MnUtilsGlobal::Gui
- Defined in:
- lib/mn_utils_gem/gui.rb
Class Method Summary collapse
- .render_component(component) ⇒ Object
- .render_component_html(component) ⇒ Object
- .validate_component(component) ⇒ Object
- .validate_json(json) ⇒ Object
Class Method Details
.render_component(component) ⇒ Object
6 7 8 9 10 |
# File 'lib/mn_utils_gem/gui.rb', line 6 def self.render_component(component) Rails.cache.fetch("gui-component-#{component}", expires_in: 1.hour) do render_component_html(component) end end |
.render_component_html(component) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mn_utils_gem/gui.rb', line 14 def self.render_component_html(component) validate_component(component) response = HTTParty.get("#{ENV['SRV_GUI_URL']}/service/gui/api/v1/component/#{component}", { timeout: 1 }) json = JSON.parse(response) validate_json(json) json['html'].html_safe rescue StandardError => e logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) logger.error("ViewHelper::render_gui_component error #{e.backtrace}") return '' end |
.validate_component(component) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mn_utils_gem/gui.rb', line 26 def self.validate_component(component) raise ArgumentError, 'Component must not be nil' \ if component.nil? raise ArgumentError, 'Component connot be blank' \ if component.blank? raise ArgumentError, 'Component must be a string' \ unless component.is_a?(String) raise ArgumentError, "ENV['SRV_GUI_URL'] is required" \ unless ENV.key? 'SRV_GUI_URL' end |
.validate_json(json) ⇒ Object
37 38 39 40 |
# File 'lib/mn_utils_gem/gui.rb', line 37 def self.validate_json(json) raise ArgumentError, 'json is empty or nil' \ if (json.nil? || json.blank?) && (json['html'].nil? || json['html'].blank?) end |