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

#add_classify_ruleObject

add classify rule



36
37
38
39
40
41
42
# File 'lib/idcf/cli/controller/extend/search_module.rb', line 36

def add_classify_rule
  Idcf::Cli::Conf::Const::CLASSIFY_RULE.each do |rule|
    ActiveSupport::Inflector.inflections do |inflect|
      inflect.irregular(*rule)
    end
  end
end

#make_model_nameObject



59
60
61
62
63
# File 'lib/idcf/cli/controller/extend/search_module.rb', line 59

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
33
# File 'lib/idcf/cli/controller/extend/search_module.rb', line 22

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

  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



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/idcf/cli/controller/extend/search_module.rb', line 47

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