Module: CoreHelper

Defined in:
lib/helpers/tmc_helpers/core_helper/core_helper.rb

Overview

This module will help the core find the right ROI and include the right class

Instance Method Summary collapse

Instance Method Details

#generate_path(class_name) ⇒ Object



20
21
22
23
24
# File 'lib/helpers/tmc_helpers/core_helper/core_helper.rb', line 20

def generate_path(class_name)
  filename = to_snake_case(class_name).concat('.rb')
  # Expecting current path to be in context of user lib. Gets all known files and tries to find this class instance
  Dir.glob('/*.rb').select { |file| file == filename }[0].gsub('.rb', '')
end

#include_user_libObject



26
27
28
# File 'lib/helpers/tmc_helpers/core_helper/core_helper.rb', line 26

def include_user_lib
  include(const_get('User' + name))
end

#require_user_libObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/helpers/tmc_helpers/core_helper/core_helper.rb', line 4

def require_user_lib
  module_path = generate_path(self.class.name)
  begin
    # Ensure file exists
    require "user_lib/#{module_path}"
  rescue
    # Return nothing if not found so doesn't depend on user_lib explicitly.
    nil
  end
end

#to_snake_case(str) ⇒ Object



15
16
17
18
# File 'lib/helpers/tmc_helpers/core_helper/core_helper.rb', line 15

def to_snake_case(str)
  # overwrite the existing to_snake_case
  str.gsub(/(?!^)([A-Z]|([?\d]{3,4}))/, '_\1').downcase
end