class ManagerWithJsonData
Attributes
url_client_data[R]
properties
Public Class Methods
new(options = nil)
click to toggle source
default constructor
Calls superclass method
ManagerBase::new
# File lib/mrpin/core/with_json/manager_with_json_data.rb, line 30 def initialize(options = nil) super(options) @url_client_data = nil end
Public Instance Methods
generate_client_json()
click to toggle source
# File lib/mrpin/core/with_json/manager_with_json_data.rb, line 73 def generate_client_json try_remove_json_old content = self.get_json_data_client path_absolute = UtilsIO.to_path_absolute(self.data_client_folder) FileUtils.mkdir_p(path_absolute) file_name = self.data_client_filename + '_' + Time.now.to_i.to_s + '.json' path_absolute_with_name = File.join(path_absolute, file_name) File.write(path_absolute_with_name, content) path_relative_with_name = UtilsIO.to_path_relative(path_absolute_with_name) @url_client_data = path_relative_with_name @logger.info("json generated: #{path_absolute_with_name}") nil end
load_init_data()
click to toggle source
Calls superclass method
ManagerBase#load_init_data
# File lib/mrpin/core/with_json/manager_with_json_data.rb, line 44 def load_init_data super check_json_data_client end
post_init()
click to toggle source
Calls superclass method
ManagerBase#post_init
# File lib/mrpin/core/with_json/manager_with_json_data.rb, line 37 def post_init super nil end
Protected Instance Methods
check_json_data_client()
click to toggle source
# File lib/mrpin/core/with_json/manager_with_json_data.rb, line 51 def check_json_data_client pattern_json = File.join(self.data_client_folder, '*.json') pattern_json = UtilsIO.to_path_absolute(pattern_json) data_client_path = File.join(self.data_client_folder, self.data_client_filename) data_client_path = UtilsIO.to_path_absolute(data_client_path) Dir[pattern_json].each do |path_absolute| if path_absolute.include?(data_client_path) path_relative = UtilsIO.to_path_relative(path_absolute) @url_client_data = path_relative break end end @logger.warn "not found any client json file for #{self.class}" if @url_client_data.nil? nil end
data_client_filename()
click to toggle source
# File lib/mrpin/core/with_json/manager_with_json_data.rb, line 15 def data_client_filename 'info' end
data_client_folder()
click to toggle source
# File lib/mrpin/core/with_json/manager_with_json_data.rb, line 10 def data_client_folder assert(false, 'please override') end
get_json_data_client()
click to toggle source
# File lib/mrpin/core/with_json/manager_with_json_data.rb, line 20 def get_json_data_client assert(false, 'please override') end
try_remove_json_old()
click to toggle source
# File lib/mrpin/core/with_json/manager_with_json_data.rb, line 98 def try_remove_json_old return if @url_client_data.blank? path_absolute = UtilsIO.to_path_absolute(@url_client_data) File.delete(path_absolute) if File.exist?(path_absolute) nil end