Module: Idcf::Cli::Controller::Extend::SearchModule

Included in:
Init
Defined in:
lib/idcf/cli/controller/extend/search_module.rb

Overview

model class search

Instance Method Summary collapse

Instance Method Details

#make_model_nameObject



49
50
51
52
53
# File 'lib/idcf/cli/controller/extend/search_module.rb', line 49

def make_model_name
  list = to_s.split('::')
  list.shift(3)
  list.join('/').underscore
end

#make_module_classesObject

make module require and class list

Returns:

  • Hash



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/idcf/cli/controller/extend/search_module.rb', line 22

def make_module_classes
  return @m_classes if @m_classes
  result = {}

  make_service_paths.each do |fn, path|
    require path
    result[fn] = path.classify.constantize
  end

  @m_classes = result
end

#make_service_pathsObject

make service paths

Returns:

  • Hash



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/idcf/cli/controller/extend/search_module.rb', line 37

def make_service_paths
  s_name    = make_model_name
  base_path = Idcf::Cli::Conf::Const::BASE_PATH
  s_path    = "#{Idcf::Cli::Conf::Const::SERVICE_PATH}/#{s_name}"
  {}.tap do |result|
    Dir.glob("#{base_path}/#{s_path}/*.rb").each do |f|
      fn         = File.basename(f, '.rb')
      result[fn] = "#{s_path}/#{fn}" unless fn =~ /^base_*/
    end
  end
end

#search_module_class(module_name) ⇒ Object

search module class

Parameters:

  • class_mame (String)

Returns:

  • Mixed



12
13
14
15
16
17
# File 'lib/idcf/cli/controller/extend/search_module.rb', line 12

def search_module_class(module_name)
  make_module_classes.each do |k, v|
    return v if module_name.to_s == k
  end
  nil
end